Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();


            TranslateButton.TouchUpInside += (object sender, EventArgs e) => {
                // Convert the phone number with text to a number
                // using PhoneTranslator.cs
                translatedNumber = PhoneTranslator.ToNumber(
                    PhoneNumberText.Text);

                // Dismiss the keyboard if text field was tapped
                PhoneNumberText.ResignFirstResponder();

                if (translatedNumber == "")
                {
                    CallButton.SetTitle("Call ", UIControlState.Normal);
                    CallButton.Enabled = false;
                }
                else
                {
                    CallButton.SetTitle("Call " + translatedNumber,
                                        UIControlState.Normal);
                    CallButton.Enabled = true;
                }
            };

            CallButton.TouchUpInside += (object sender, EventArgs e) => {
                //Store the phone number that we're dialing in PhoneNumbers
                PhoneNumbers.Add(translatedNumber);

                var url = new NSUrl("tel:" + translatedNumber);

                // Use URL handler with tel: prefix to invoke Apple's Phone app,
                // otherwise show an alert dialog
                if (!UIApplication.SharedApplication.OpenUrl(url))
                {
                    var alert = UIAlertController.Create("Not supported", "Scheme 'tel:' is not supported on this device", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            };


            //
            // Nativation without Segues
            // - if the segue was deleted from the storyboard, this code would enable the button to open the second view controller
            //
            CallHistoryButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                // Launches a new instance of CallHistoryController
                CallHistoryController callHistory = this.Storyboard.InstantiateViewController("CallHistoryController") as CallHistoryController;
                if (callHistory != null)
                {
                    callHistory.PhoneNumbers = PhoneNumbers;
                    this.NavigationController.PushViewController(callHistory, true);
                }
            };
        }
Пример #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            var phoneNumberText = FindViewById <EditText>(Resource.Id.PhoneNumberText);
            var translateButton = FindViewById <Button>(Resource.Id.TranslateButton);
            var callButton      = FindViewById <Button>(Resource.Id.CallButton);

            callButton.Enabled = false;

            var translatedNumber = Empty;

            translateButton.Click += (sender, e) =>
            {
                translatedNumber = PhoneTranslator.ToNumber(phoneNumberText.Text);

                if (IsNullOrWhiteSpace(translatedNumber))
                {
                    callButton.Text    = "Call";
                    callButton.Enabled = false;
                }
                else
                {
                    callButton.Text    = $"Call #{translatedNumber}";
                    callButton.Enabled = true;
                }
            };

            callButton.Click += (sender, args) =>
            {
                var callDialog = new AlertDialog.Builder(this);

                callDialog.SetMessage($"Call #{translatedNumber}?");

                callDialog.SetNeutralButton("Call", (o, eventArgs) =>
                {
                    var callIntent = new Intent(Intent.ActionCall);

                    callIntent.SetData(Uri.Parse("tel:" + translatedNumber));

                    StartActivity(callIntent);
                });

                callDialog.SetNegativeButton("Cancel", (o, eventArgs) => { });

                callDialog.Show();
            };
        }
Пример #3
0
 void OnTranslate(object sender, EventArgs e)
 {
     translatedNumber = PhoneTranslator.ToNumber(phoneNumberText.Text);
     if (!string.IsNullOrWhiteSpace(translatedNumber))
     {
         callButton.IsEnabled = true;
         callButton.Text      = "Call" + translatedNumber;
     }
     else
     {
         callButton.IsEnabled = false;
         callButton.Text      = "Call";
     }
 }
Пример #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            string translatedNumber = "";

            TranslateButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                // Convert the phone number with text to a number
                // using PhoneTranslator.cs
                translatedNumber = PhoneTranslator.ToNumber(
                    PhoneNumberText.Text);

                // Dismiss the keyboard if text field was tapped
                PhoneNumberText.ResignFirstResponder();

                if (translatedNumber == "")
                {
                    CallButton.SetTitle("Call ", UIControlState.Normal);
                    CallButton.Enabled = false;
                }
                else
                {
                    CallButton.SetTitle("Call " + translatedNumber,
                                        UIControlState.Normal);
                    CallButton.Enabled = true;
                }
            };

            CallButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                // Use URL handler with tel: prefix to invoke Apple's Phone app...
                var url = new NSUrl("tel:" + translatedNumber);

                // ...otherwise show an alert dialog
                if (!UIApplication.SharedApplication.OpenUrl(url))
                {
                    var alert = UIAlertController.Create("Not supported", "Scheme 'tel:' is not supported on this device", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            };;
        }
Пример #5
0
        //Activity生命周期,通过重写其方法,可以控制活动的加载方式和与用户的互动方式,甚至还可以控制活动从设备屏幕消失后会发生的情况

        /// <summary>
        /// 创建视图、初始化变量,并执行在用户能看到活动之前其他必须完成的准备工作。 只有将活动加载到内存时,才会调用此方法一次。
        /// </summary>
        /// <param name="savedInstanceState"></param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            // Get our UI controls from the loaded layout
            EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
            TextView translatedPhoneWord = FindViewById<TextView>(Resource.Id.TranslatedPhoneword);
            Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);

            Button translationHistoryButton = FindViewById<Button>(Resource.Id.TranslationHistoryButton);

            // Add code to translate number
            translateButton.Click += (sender, e) =>
            {
                // Translate user's alphanumeric phone number to numeric
                string translatedNumber = PhoneTranslator.ToNumber(phoneNumberText.Text);
                if (string.IsNullOrWhiteSpace(translatedNumber))
                {
                    translatedPhoneWord.Text = string.Empty;
                }
                else
                {
                    translatedPhoneWord.Text = translatedNumber;
                    phoneNumbers.Add(translatedNumber);
                    translationHistoryButton.Enabled = true;
                }
            };


            translationHistoryButton.Click += (sender, e) =>
            {
                //创建一个Intent,传入当前上下文(this,用于引用当前上下文)以及你所查找的应用程序块的类型 (TranslationHistoryActivity):
                var intent = new Intent(this, typeof(TranslationHistoryActivity));
                //PutStringArrayExtra 用于将电话号码列表附加到Intent,而 StartActivity 会对Intent的收件人进行调用
                intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
                StartActivity(intent);
            };


        }
Пример #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

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

            // Get UI controls from the loaded layout
            EditText phoneNumberText          = FindViewById <EditText>(Resource.Id.PhoneNumberText);
            TextView translatedPhoneWord      = FindViewById <TextView>(Resource.Id.TranslatedPhoneWord);
            Button   translateButton          = FindViewById <Button>(Resource.Id.TranslateButton);
            Button   translationHistoryButton = FindViewById <Button>(Resource.Id.TranslationHistoryButton);

            // Add code to translate number
            string translatedNumber = string.Empty;

            translateButton.Click += (sender, e) =>
            {
                // Translate user's alphanumeric phone number to numeric
                translatedNumber = PhoneTranslator.ToNumber(phoneNumberText.Text);
                if (string.IsNullOrWhiteSpace(translatedNumber))
                {
                    translatedPhoneWord.Text = string.Empty;
                }
                else
                {
                    translatedPhoneWord.Text = translatedNumber;
                    phoneNumbers.Add(translatedNumber);
                    translationHistoryButton.Enabled = true;
                }
            };

            translationHistoryButton.Click += (sender, e) =>
            {
                var intent = new Intent(this, typeof(TranslationHistoryActivity));
                intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
                StartActivity(intent);
            };
        }
Пример #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            string translatedNumber = "";

            TranslateButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                translatedNumber = PhoneTranslator.ToNumber(PhoneTextNumber.Text);

                PhoneTextNumber.ResignFirstResponder();

                if (translatedNumber == "")
                {
                    CallButton.SetTitle("Call", UIControlState.Normal);
                    CallButton.Enabled = false;
                }
                else
                {
                    CallButton.SetTitle("Call" + translatedNumber, UIControlState.Normal);
                    CallButton.Enabled = true;
                }
            };

            CallButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var url = new NSUrl("tel:" + translatedNumber);
                if (UIApplication.SharedApplication.OpenUrl(url))
                {
                    var alert = UIAlertController.Create("Not supported", "Scheme 'tel:' is not supported on this device", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            };
        }
Пример #8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            string translatedNumber = "";

            TranslateButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                // Convert the phone number with text to a number
                // using PhoneTranslator.cs
                translatedNumber = PhoneTranslator.ToNumber(PhoneNumberText.Text);

                // 키보드 해제
                PhoneNumberText.ResignFirstResponder();

                if (translatedNumber == "")
                {
                    CallButton.SetTitle("Call", UIControlState.Normal);
                    CallButton.Enabled = false;
                }
                else
                {
                    CallButton.SetTitle("Call " + translatedNumber, UIControlState.Normal);
                    CallButton.Enabled = true;
                }
            };


            CallButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                PhoneNumbers.Add(translatedNumber);
                var url = new NSUrl("tel:" + translatedNumber);

                // Use URL handler with tel: prefix to invoke Apple's Phone app,
                // otherwise show an alert dialog

                if (!UIApplication.SharedApplication.OpenUrl(url))
                {
                    var alert = UIAlertController.Create("Not supported", "Scheme 'tel:' is not supported on this device", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            };

            //Segue 없이 탐색
            //CallHistoryButton.TouchUpInside += (object sender, EventArgs e) =>
            //{
            //    CallHistoryController callHistory = this.Storyboard.InstantiateViewController("CallHistoryController") as CallHistoryController;
            //    if (callHistory != null)
            //    {
            //        callHistory.PhoneNumbers = PhoneNumbers;
            //        this.NavigationController.PushViewController(callHistory, true);
            //    }
            //};

            //CAGradientLayer gradient = new CAGradientLayer();
            //gradient.Frame = this.CallButton.Frame;
            //gradient.Colors = new CGColor[] {UIColor.Yellow.CGColor , UIColor.Blue.CGColor};
            //gradient.StartPoint = new CGPoint(0.0, 0.5);
            //gradient.EndPoint = new CGPoint(0.5, 0.5);
            //gradient.Locations = new NSNumber[] {Convert.NS(this.CallButton.Frame.Location.X), this.CallButton.Frame.Location.X };

            //CallButton.Layer.InsertSublayer(gradient, 0);
            //CallButton.Layer.CornerRadius = CallButton.Frame.Size.Height / 2;
            //CallButton.Layer.BorderWidth = 5.0f;
        }