예제 #1
0
        void SendMessageTOListButtun(object sender, EventArgs e)
        {
            MessageStruct messageStruct = new MessageStruct(entryMessage.Text, true, false);

            TCPListener.stream.Write(StructToBytes(messageStruct), 0, StructToBytes(messageStruct).Length);
            SendMessageTOList(entryMessage.Text, TextAlignment.End);
            entryMessage.Text = "";
        }
예제 #2
0
        void OverTalkButtun(object sender, EventArgs e)
        {
            IfTalk.If = false;
            MessageStruct messageStruct = new MessageStruct("", true, true);

            TCPListener.stream.Write(StructToBytes(messageStruct), 0, StructToBytes(messageStruct).Length);
            var page = new Match();

            Application.Current.MainPage = new Match();
        }
예제 #3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



        public Call()
        {
            BackgroundImage = "callbackground";
            message.Clear();
            Label header = new Label
            {
                WidthRequest      = 300,
                Text              = "TwoTalk",
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };
            Button outButton = new Button
            {
                Text            = "Out",
                BackgroundColor = Color.Pink
            };
            StackLayout Headers = new StackLayout
            {
                Spacing       = 5,
                HeightRequest = 40,
                Orientation   = StackOrientation.Horizontal,
                Children      =
                {
                    header,
                    outButton
                }
            };

            outButton.Clicked += OverTalkButtun;


            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            MessageList = new ListView
            {
                ItemsSource    = message,
                SeparatorColor = Color.Transparent,
                RowHeight      = 80,

                ItemTemplate = new DataTemplate(() =>
                {
                    HeightRequest      = 120;
                    Label timeLabel    = new Label();
                    Label messageLabel = new Label();
                    // Create views with bindings for displaying each property.
                    timeLabel.SetBinding(Label.TextProperty, "Time");
                    timeLabel.HeightRequest = 20;
                    timeLabel.SetBinding(Label.HorizontalTextAlignmentProperty, "Horizon");
                    timeLabel.VerticalTextAlignment = TextAlignment.Start;
                    messageLabel.SetBinding(Label.TextProperty, "AMessage");
                    messageLabel.HeightRequest         = 30;
                    messageLabel.VerticalTextAlignment = TextAlignment.End;
                    messageLabel.SetBinding(Label.HorizontalTextAlignmentProperty, "Horizon");
                    messageLabel.TextColor = Color.Black;
                    messageLabel.FontSize  = 20;


                    return(new ViewCell
                    {
                        View = new StackLayout
                        {
                            BackgroundColor = Color.Transparent,
                            HeightRequest = 120,
                            Padding = new Thickness(5, 5, 5, 5),
                            Children =
                            {
                                timeLabel,
                                messageLabel
                            }
                        }
                    });
                })
            };

            sendButton.Clicked += SendMessageTOListButtun;


            StackLayout Send = new StackLayout
            {
                Spacing       = 5,
                HeightRequest = 60,
                Orientation   = StackOrientation.Horizontal,
                Children      =
                {
                    entryMessage,
                    sendButton
                }
            };


            // Accomodate iPhone status bar.
            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            // Build the page.
            this.Content = new StackLayout
            {
                Children =
                {
                    Headers,
                    MessageList,
                    Send
                }
            };
            var p = new IfTalk();

            p.SetIf(true);
            Task.Run(() =>
            {
                while (true)
                {
                    if (IfTalk.If == false)
                    {
                        break;
                    }
                    var data_ = new Byte[270];
                    TCPListener.stream.Read(data_, 0, data_.Length);
                    MessageStruct m = BytesToStruct <MessageStruct>(data_);
                    if (!m.ifTo)
                    {
                        if (!m.ifOver)
                        {
                            Device.BeginInvokeOnMainThread(() => SendMessageTOList(BytesToStruct <MessageStruct>(data_).str, TextAlignment.Start));
                        }
                        else
                        {
                            IfTalk.If = false;
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                Android.Widget.Toast.MakeText(Forms.Context, "your listener has left..", Android.Widget.ToastLength.Short).Show();
                                var page = new Match();
                                Application.Current.MainPage = new Match();
                            });
                        }
                    }
                }
            });
        }