Exemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            SettingsData settingsData = SettingsLoader.Load();

            contactData = settingsData.ContactData;
            messageItem = settingsData.Message;

            // Get our button from the layout resource,
            // and attach an event to it
            selectContactButton              = FindViewById <Button> (Resource.Id.selectContactButton);
            selectContactButton.Text         = ContactDataFormatter.Format(contactData);
            selectContactButton.TextChanged += delegate(object sender, Android.Text.TextChangedEventArgs e) {
                UpdateButtonsStatus();
            };

            messageEditText      = FindViewById <EditText> (Resource.Id.message1EditText);
            messageEditText.Text = MessageItemFormatter.Format(messageItem);
            // http://stackoverflow.com/questions/6217378/place-cursor-at-the-end-of-text-in-edittext
            messageEditText.SetSelection(messageEditText.Text.Length);

            sendSmsMessageButton      = FindViewById <Button> (Resource.Id.sendSmsButton);
            sendSmsMessageButton.Text = "Send SMS";

            definedButtons[0] = FindViewById <Button> (Resource.Id.send1Button);
            definedButtons[1] = FindViewById <Button> (Resource.Id.send2Button);
            definedButtons[2] = FindViewById <Button> (Resource.Id.send3Button);
            definedButtons[3] = FindViewById <Button> (Resource.Id.send4Button);
            definedButtons[4] = FindViewById <Button> (Resource.Id.send5Button);

            for (int i = 0; i < definedMessages.Length; i++)
            {
                definedButtons[i].Text = String.Format("Send '{0}'", definedMessages [i]);
            }

            selectContactButton.Click += delegate {
                //Create a new intent for choosing a contact
                var contactPickerIntent = new Intent(Intent.ActionPick, Android.Provider.ContactsContract.Contacts.ContentUri);
                contactPickerIntent.SetType(ContactsContract.CommonDataKinds.Phone.ContentType);                  //(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
                // Start the contact picker expecting a result with the resultCode '101'
                StartActivityForResult(contactPickerIntent, SELECT_CONTACT_SUCCESS_RESULT);
            };

            var piSent      = PendingIntent.GetBroadcast(this, 0, new Intent("SMS_SENT"), 0);
            var piDelivered = PendingIntent.GetBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0);

            sendSmsMessageButton.Click += delegate(object sender, EventArgs e) {
                var messageText = messageEditText.Text;
                if (contactData != null && !contactData.Empty && !String.IsNullOrEmpty(messageText))
                {
                    messageText = Processing(messageText);
                    SmsManager.Default.SendTextMessage(contactData.PhoneNumber, null, messageText, piSent, piDelivered);
                    AddSentSmsToHistory(contactData.PhoneNumber, messageText);
                }
            };

            for (int i = 0; i < definedButtons.Length; i++)
            {
                string messageText = definedMessages [i];
                definedButtons [i].Click += delegate(object sender, EventArgs e) {
                    if (contactData != null && !contactData.Empty && !String.IsNullOrEmpty(messageText))
                    {
                        messageText = Processing(messageText);
                        SmsManager.Default.SendTextMessage(contactData.PhoneNumber, null, messageText, piSent, piDelivered);
                        AddSentSmsToHistory(contactData.PhoneNumber, messageText);
                    }
                };
            }
            ;

            UpdateButtonsStatus();
            InitializeLocationManager();
        }
Exemplo n.º 2
0
 public SettingsData(ContactData contactData, MessageItem message)
 {
     ContactData = contactData;
     Message     = message;
 }