public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);

            var progess = new ProgressDialog
                          .Builder(Context)
                          .SetMessage(Resource.String.contacting)
                          .Create();

            var name     = view.FindViewById <EditText>(Resource.Id.name);
            var email    = view.FindViewById <EditText>(Resource.Id.email);
            var phone    = view.FindViewById <EditText>(Resource.Id.phone);
            var website  = view.FindViewById <EditText>(Resource.Id.website);
            var position = view.FindViewById <EditText>(Resource.Id.position);
            var message  = view.FindViewById <EditText>(Resource.Id.message);
            var send     = view.FindViewById <Button>  (Resource.Id.send);

            var submit = Observable.Merge(
                name.RxKeyPressed(),
                email.RxKeyPressed(),
                phone.RxKeyPressed(),
                website.RxKeyPressed(),
                position.RxKeyPressed(),
                message.RxKeyPressed()
                ).Where(_ => _ == Keycode.Enter)
                         .Select(_ => Unit.Default)
                         .Merge(send.RxClick());

            Observable.CombineLatest(
                name.RxTextChanged().StartWith(string.Empty),
                email.RxTextChanged().StartWith(string.Empty),
                phone.RxTextChanged().StartWith(string.Empty),
                website.RxTextChanged().StartWith(string.Empty),
                position.RxTextChanged().StartWith(string.Empty),
                message.RxTextChanged().StartWith(string.Empty)
                , Tuple.Create)
            .SampleLatest(submit)
            .Do(_ =>
                OnClean(name, email, phone, website, position, message))
            .Do(_ => progess.Show())
            .SelectMany(_ =>
                        OnValidate(
                            Tuple.Create(name, _.Item1),
                            Tuple.Create(email, _.Item2),
                            Tuple.Create(phone, _.Item3),
                            Tuple.Create(website, _.Item4),
                            Tuple.Create(position, _.Item5),
                            Tuple.Create(message, _.Item6))
                        .Catch <ContactInfo, Exception>(e => {
                OnError(progess);
                return(Observable.Empty <ContactInfo>());
            }))
            .Select(_ => Section.Welcome)
            .Do(_ => progess.Dismiss())
            .Do(_ => Toast.MakeText(Context, Resource.String.contact_sent, ToastLength.Long).Show())
            .Subscribe(Nav)
            .AddTo(Disposables);
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Today);

            Window.DecorView.SetBackgroundColor(Color.Purple);

            ISharedPreferences       Time  = Application.Context.GetSharedPreferences("Time", FileCreationMode.Private);
            ISharedPreferencesEditor ETime = Time.Edit();

            string CurrentDay = DateTime.Now.Day.ToString();

            ISharedPreferences       userInfo = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
            ISharedPreferencesEditor edit     = userInfo.Edit();

            EditText PrNAme = FindViewById <EditText>(Resource.Id.editText1);

            PrNAme.SetHeight(MainActivity.GetHeightPixels / MainActivity.EDIT_TEXT_COEFF);
            PrNAme.SetBackgroundColor(Color.BlueViolet);

            EditText PrMass = FindViewById <EditText>(Resource.Id.editText2);

            PrMass.SetHeight(MainActivity.GetHeightPixels / MainActivity.EDIT_TEXT_COEFF);
            PrMass.SetBackgroundColor(Color.BlueViolet);

            TextView dayCalories = FindViewById <TextView>(Resource.Id.textView1);

            dayCalories.SetHeight(MainActivity.GetHeightPixels / MainActivity.TEXTVIEW_COEFF);
            dayCalories.SetTextColor(Color.Black);
            if (CurrentDay != Time.GetString("Day", null))
            {
                edit.Remove("DayCalories");
                edit.PutString("DayCalories", "0");
                edit.Apply();
                ETime.Remove("Day");
                ETime.PutString("Day", CurrentDay);
                ETime.Apply();
            }
            dayCalories.Text = userInfo.GetString("DayCalories", "0");

            TextView DailyRate = FindViewById <TextView>(Resource.Id.textView2);

            DailyRate.SetHeight(MainActivity.GetHeightPixels / MainActivity.TEXTVIEW_COEFF);
            DailyRate.SetTextColor(Color.Black);
            DailyRate.Text = "Daily rate: " + userInfo.GetString("DailyRate", "0");

            TextView space = FindViewById <TextView>(Resource.Id.textView3);

            space.SetHeight(MainActivity.GetHeightPixels / MainActivity.TEXTVIEW_COEFF / 5);

            Button Add = FindViewById <Button>(Resource.Id.button1);

            Add.SetHeight(MainActivity.GetHeightPixels / MainActivity.BUTTON_COEFF);

            Add.Click += delegate
            {
                double       currentCalories    = 0;
                double       newCurrentCalories = 0;
                string       fName  = null;
                string       fValue = null;
                double       FValue = 0;
                StreamReader str    = new StreamReader(Assets.Open("Food.txt"));
                int          count  = 0;
                try                                      //start try
                {
                    while (!str.EndOfStream)
                    {
                        count  = 0;
                        fName  = null;
                        fValue = "";
                        string line = str.ReadLine();
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] == '-')
                            {
                                count = i;
                            }
                        }
                        for (int i = 0; i < count; i++)
                        {
                            fName += line[i];
                        }
                        if (PrNAme.Text.ToLower() == fName)
                        {
                            for (int i = count + 1; line[i] != ','; i++)
                            {
                                fValue += line[i];
                                count++;
                            }
                            break;
                        }
                    }
                    FValue = double.Parse(fValue);
                    double ProductMass;
                    ProductMass        = double.Parse(PrMass.Text) / 100;
                    currentCalories    = Convert.ToDouble(userInfo.GetString("DayCalories", "0"));
                    newCurrentCalories = currentCalories + (FValue * ProductMass);
                    edit.Remove("DayCalories");
                    edit.PutString("DayCalories", newCurrentCalories.ToString());
                    edit.Apply();
                    dayCalories.Text = userInfo.GetString("DayCalories", "0");

                    str.Close();
                }

                catch (FormatException)
                {
                    var dialog = new ProgressDialog.Builder(this);
                    dialog.SetMessage("Error");
                    dialog.SetPositiveButton("OK", delegate { });
                    dialog.Show();
                }
                catch (IndexOutOfRangeException)
                {
                    var dialog = new ProgressDialog.Builder(this);
                    dialog.SetMessage("Error");
                    dialog.SetNegativeButton("OK", delegate { });
                    dialog.Show();
                }
                catch (FileNotFoundException)
                {
                    var dialog = new ProgressDialog.Builder(this);
                    dialog.SetMessage("Error");
                    dialog.SetNegativeButton("OK", delegate { });
                    dialog.Show();
                }
            };
        }
Exemple #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            Window.DecorView.SetBackgroundColor(Color.Purple);

            int d = Resources.DisplayMetrics.HeightPixels;

            Button button = FindViewById <Button>(Resource.Id.button1);

            button.SetHeight(d / MainActivity.BUTTON_COEFF);

            EditText editText1 = FindViewById <EditText>(Resource.Id.editText1);

            editText1.SetHeight(d / MainActivity.EDIT_TEXT_COEFF);
            editText1.SetBackgroundColor(Color.BlueViolet);

            EditText editText2 = FindViewById <EditText>(Resource.Id.editText2);

            editText2.SetHeight(d / MainActivity.EDIT_TEXT_COEFF);
            editText2.SetBackgroundColor(Color.BlueViolet);

            TextView view1 = FindViewById <TextView>(Resource.Id.textView1);

            view1.SetHeight(d / MainActivity.TEXTVIEW_COEFF);

            TextView view2 = FindViewById <TextView>(Resource.Id.textView2);

            view2.SetHeight(d / MainActivity.TEXTVIEW_COEFF);

            TextView view3 = FindViewById <TextView>(Resource.Id.textView3);

            view3.SetHeight(d / MainActivity.TEXTVIEW_COEFF);

            TextView view4 = FindViewById <TextView>(Resource.Id.textView4);

            view4.SetHeight(d / MainActivity.TEXTVIEW_COEFF);

            TextView view5 = FindViewById <TextView>(Resource.Id.textView5);

            view5.SetHeight(d / MainActivity.TEXTVIEW_COEFF);

            TextView view6 = FindViewById <TextView>(Resource.Id.textView6);

            view6.SetHeight(d / MainActivity.TEXTVIEW_COEFF);

            TextView Space = FindViewById <TextView>(Resource.Id.textView7);

            Space.SetHeight(d / MainActivity.TEXTVIEW_COEFF / 5);

            InputMethodManager inputManager = (InputMethodManager)this.GetSystemService(Context.InputMethodService);

            view1.Touch += delegate
            {
                inputManager.HideSoftInputFromWindow(editText1.WindowToken, 0);
                inputManager.HideSoftInputFromWindow(editText2.WindowToken, 0);
            };

            view2.Touch += delegate
            {
                inputManager.HideSoftInputFromWindow(editText1.WindowToken, 0);
                inputManager.HideSoftInputFromWindow(editText2.WindowToken, 0);
            };

            view3.Touch += delegate
            {
                inputManager.HideSoftInputFromWindow(editText1.WindowToken, 0);
                inputManager.HideSoftInputFromWindow(editText2.WindowToken, 0);
            };

            view4.Touch += delegate
            {
                inputManager.HideSoftInputFromWindow(editText1.WindowToken, 0);
                inputManager.HideSoftInputFromWindow(editText2.WindowToken, 0);
            };

            view5.Touch += delegate
            {
                inputManager.HideSoftInputFromWindow(editText1.WindowToken, 0);
                inputManager.HideSoftInputFromWindow(editText2.WindowToken, 0);
            };

            view6.Touch += delegate
            {
                inputManager.HideSoftInputFromWindow(editText1.WindowToken, 0);
                inputManager.HideSoftInputFromWindow(editText2.WindowToken, 0);
            };

            editText1.Click += delegate
            {
                editText1.Text = null;
                double f = 0;
                double.TryParse(editText2.Text, out f);
                if (f != 0)
                {
                    editText2.Text = "";
                }
            };

            editText2.Click += delegate
            {
                editText2.Text = null;
            };

            button.Click += delegate
            {
                double       q         = 0;
                string       fName     = null;
                string       fValue    = null;
                string       protValue = null;
                string       fatValue  = null;
                string       uglValue  = null;
                int          FValue    = 0;
                StreamReader str       = new StreamReader(Assets.Open("Food.txt"));
                int          count     = 0;
                try
                {
                    while (!str.EndOfStream)
                    {
                        count     = 0;
                        fName     = null;
                        fValue    = "";
                        protValue = null;
                        fatValue  = null;
                        uglValue  = null;
                        string line = str.ReadLine();
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] == '-')
                            {
                                count = i;
                            }
                        }
                        for (int i = 0; i < count; i++)
                        {
                            fName += line[i];
                        }
                        if (editText1.Text.ToLower() == fName)
                        {
                            for (int i = count + 1; line[i] != ','; i++)
                            {
                                fValue += line[i];
                                count++;
                            }
                            for (int i = count + 2; line[i] != '?'; i++)
                            {
                                protValue += line[i];
                                count++;
                            }
                            for (int i = count + 3; line[i] != '!'; i++)
                            {
                                fatValue += line[i];
                                count++;
                            }
                            for (int i = count + 4; i < line.Length; i++)
                            {
                                uglValue += line[i];
                                count++;
                            }
                            break;
                        }
                    }
                    FValue     = int.Parse(fValue);
                    view2.Text = "Proteins: " + protValue.ToString();
                    view3.Text = "Fats: " + fatValue.ToString();
                    view4.Text = "carbohydrates: " + uglValue.ToString();
                    view5.Text = "Calories: " + FValue.ToString();
                    double f = 0;
                    double.TryParse(editText2.Text, out f);
                    if (f == 0)
                    {
                        view6.Text = "Total calories: 0";
                    }
                    else
                    {
                        view6.Text = "Total calories: " + FValue * (double.Parse(editText2.Text) / 100);
                    }
                }
                catch (FormatException)
                {
                    var dialog = new ProgressDialog.Builder(this);
                    dialog.SetMessage("Error");
                    dialog.SetPositiveButton("OK", delegate { });
                    dialog.Show();
                }
                catch (IndexOutOfRangeException)
                {
                    var dialog = new ProgressDialog.Builder(this);
                    dialog.SetMessage("Error");
                    dialog.SetNegativeButton("OK", delegate { });
                    dialog.Show();
                }
                catch (FileNotFoundException)
                {
                    var dialog = new ProgressDialog.Builder(this);
                    dialog.SetMessage("Error");
                    dialog.SetNegativeButton("OK", delegate { });
                    dialog.Show();
                }
            };
        }