public void SendMessage(XmppConnection Connection, string To, string Message, bool IM) { if (!IM) { if (encrypt) { Connection.GetXmppClient().SendMessage(To, encryption.EncryptString(Message, Password)); } else { Connection.GetXmppClient().SendMessage(To, Message); } } else { if (encrypt) { Connection.GetXmppIm().SendMessage(To, encryption.EncryptString(Message, Password)); } else { Connection.GetXmppIm().SendMessage(To, Message); } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); ConnectivityManager connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService); NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo; bool isOnline = (activeConnection != null) && activeConnection.IsConnected; if (!isOnline) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("No network access!"); alert.SetMessage("Can't connect to server. No network access."); alert.SetPositiveButton("OK", (senderAlert, args) => { Finish(); }); Dialog dialog = alert.Create(); dialog.Show(); } else { SetContentView(Resource.Layout.Main); Log.Debug("Start", "Started"); LoadValues(); if (string.IsNullOrEmpty(UserAc)) { StartActivity(typeof(LoginActivity)); Finish(); } else { ImageButton sendbutton = FindViewById <ImageButton>(Resource.Id.imageButtonSend); ImageButton smilebutton = FindViewById <ImageButton>(Resource.Id.imgButtonSmile); edit = FindViewById <EditText>(Resource.Id.editTextMessage); chatlay = FindViewById <LinearLayout>(Resource.Id.linearLayoutchat); scrollview = FindViewById <ScrollView>(Resource.Id.scrollviewchat); onlineimg = FindViewById <ImageView>(Resource.Id.imageViewStatus); onlinetxt = FindViewById <TextView>(Resource.Id.textViewStatus); sendbutton.Click += delegate { SendMessage(null); }; smilebutton.Click += delegate { Log.Debug("Smile Activity", "Smile Activity started"); StartActivity(typeof(SmileActivity)); }; System.Threading.Timer timer = new System.Threading.Timer((e) => { if (ScrollDown) { RunOnUiThread(() => { scrollview.FullScroll(FocusSearchDirection.Down); ScrollDown = false; }); } if (Smile) { RunOnUiThread(() => { Smile = false; message.SendMessage(connection.GetXmppIm(), ReceiverJID, SmileCode); ImageView img = new ImageView(this); img.SetImageDrawable(SmileActivity.GetSmileImage(this, SmileCodeIM)); img.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); chatlay.AddView(img); ScrollDown = true; }); } }, null, 500, 200); System.Threading.Timer timerstatus = new System.Threading.Timer((e) => { connection.SetONIM(true); }, null, 5000, 15000); string usr = "******" + UserAc; if (Administrator) { ReceiverJID = usr + "@" + XmppConnection.Server; usr = "******" + usr; } else { ReceiverJID = "Admin_" + usr + "@" + XmppConnection.Server; } vibrator = (Vibrator)GetSystemService(VibratorService); connection.ConnectToXMPPIM(usr, PasswordAc); Log.Debug("XMPP", "Connected as " + connection.GetXmppIm().Jid); connection.GetXmppIm().Message += Connection_Message; connection.AddToRoster(ReceiverJID); connection.GetXmppIm().RequestSubscription(ReceiverJID); connection.ApproveRequest(ReceiverJID); connection.GetXmppIm().Status += Connection_Status; } } }