Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            SetContentView(Resource.Layout.activity_main);
            Button   calculateButton  = FindViewById <Button>(Resource.Id.CalculateButton);
            TextView errorText        = FindViewById <TextView>(Resource.Id.errorText);
            Button   methodSelectBtn  = FindViewById <Button>(Resource.Id.MethodSelectBtn);
            EditText nbOfPrimeNumbers = FindViewById <EditText>(Resource.Id.NbOfPrimeNumbers);

            string methodRec = Intent.GetStringExtra("Method");
            string method    = "Straight";

            if (!(methodRec is null))
            {
                method = methodRec;
            }

            calculateButton.Click += (s, e) =>
            {
                try {
                    int    givenNbPrimes      = PrimeCalculation.ToNumber(nbOfPrimeNumbers.Text);
                    Intent resultScreenIntent = new Intent(this, typeof(ToResultScreen));
                    resultScreenIntent.PutExtra("nbPrimes", givenNbPrimes);
                    resultScreenIntent.PutExtra("Method", method);

                    StartActivity(resultScreenIntent);
                }
                catch (Exception ex)
                {
                    errorText.Text = "Please enter an integer";
                }
            };

            methodSelectBtn.Click += (s, e) =>
            {
                {
                    Intent MethodScreenIntent = new Intent(this, typeof(ToMethodScreen));
                    StartActivity(MethodScreenIntent);
                }
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            int    givenNbPrimes = Intent.GetIntExtra("nbPrimes", 0);
            string methodRec     = Intent.GetStringExtra("Method");

            string method = "Straight";

            if (!(methodRec is null))
            {
                method = methodRec;
            }

            SetContentView(Resource.Layout.resultScreen);
            TextView methodTxt           = FindViewById <TextView>(Resource.Id.MethodTxt);
            TextView result              = FindViewById <TextView>(Resource.Id.result);
            TextView calculationTimeText = FindViewById <TextView>(Resource.Id.calculationTimeText);

            string text;

            if (method == "Sieve")
            {
                text = "Sieve of Eratosthenes";
            }
            else
            {
                text = "Straightforward";
            }
            methodTxt.Text = text;

            PrimeCalculation currentCalculation = new PrimeCalculation(givenNbPrimes, method);
            string           primeNumbers       = currentCalculation.result;
            double           calculationTime    = currentCalculation.calculationTime;

            result.Text = primeNumbers;
            calculationTimeText.Text = calculationTime.ToString() + " miliseconds";
        }