private void configurePickerRanges() { if (mIs24HourView) { mHourPicker.MinValue = (0); mHourPicker.MaxValue = (23); mHourPicker.SetFormatter(TWO_DIGIT_FORMATTER); mAmPmButton.Visibility = ViewStates.Gone; } else { mHourPicker.MinValue = (1); mHourPicker.MaxValue = (12); mHourPicker.SetFormatter(null); mAmPmButton.Visibility = ViewStates.Visible; } }
//--------------------------------------------------------------------------------------------------------------------------------------------------- //Adding a new product. private void ListForChoosingProducts_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { //Creating a new layout for entering a number of grams. AlertDialog.Builder Object = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.From(this); LinearLayout layout = new LinearLayout(this); View product_Quantity = inflater.Inflate(Resource.Layout.product_Quantity, layout); Object.SetView(product_Quantity); //Elements from the layout. NumberPicker ProductAmount = product_Quantity.FindViewById <NumberPicker>(Resource.Id.AmountPicker); ProductAmount.MinValue = 1; ProductAmount.MaxValue = 1000; ProductAmount.SetFormatter(new HelpclassNumberPickerFormatter()); //Action on pressing positive button. Object.SetPositiveButton(Resource.String.OK, new EventHandler <DialogClickEventArgs>(delegate(object Sender, DialogClickEventArgs e1) { //Creating a new product and adding it to the user's list of products. Product TempProduct = DatabaseProducts.GetProduct(ListForProducts.ElementAt(e.Position)); TempProduct.Setter(ProductAmount.Value * 10, DateTime.Now); User TempUser = DatabaseUser.GetUser(User.CurrentUser); TempUser.Products.Add(TempProduct); DatabaseUser.SQConnection.UpdateWithChildren(TempUser); })); //Action on pressing negative button. Object.SetNegativeButton(Resource.String.Cancel, new EventHandler <DialogClickEventArgs>(delegate(object Sender, DialogClickEventArgs e1){})); //Showing the form. Object.Show(); }
public TimePicker(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService); inflater.Inflate(Resource.Layout.time_picker_widget, this, true); // hour mHourPicker = (NumberPicker)FindViewById(Resource.Id.hour); mHourPicker.SetOnValueChangedListener(new OnValueChangeListener() { OnValueChanged = (NumberPicker picker, int oldVal, int newVal) => { // TODO Auto-generated method stub mCurrentHour = newVal; if (!mIs24HourView) { // adjust from [1-12] to [0-11] internally, with the times // written "12:xx" being the start of the half-day if (mCurrentHour == 12) { mCurrentHour = 0; } if (!mIsAm) { // PM means 12 hours later than nominal mCurrentHour += 12; } } onTimeChanged(); } }); // digits of minute mMinutePicker = (NumberPicker)FindViewById(Resource.Id.minute); mMinutePicker.MinValue = 0; mMinutePicker.MaxValue = 59; mMinutePicker.SetFormatter(TWO_DIGIT_FORMATTER); mMinutePicker.SetOnValueChangedListener(new Droid.OnValueChangeListener() { OnValueChanged = (NumberPicker spinner, int oldVal, int newVal) => { mCurrentMinute = newVal; onTimeChanged(); } }); // digits of seconds mSecondPicker = (NumberPicker)FindViewById(Resource.Id.seconds); mSecondPicker.MinValue = 0; mSecondPicker.MaxValue = 59; mSecondPicker.SetFormatter(TWO_DIGIT_FORMATTER); mSecondPicker.SetOnValueChangedListener(new Droid.OnValueChangeListener() { OnValueChanged = (NumberPicker spinner, int oldVal, int newVal) => { mCurrentSeconds = newVal; onTimeChanged(); } }); mAmPmButton = (Button)FindViewById(Resource.Id.amPm); // now that the hour/minute picker objects have been initialized, set // the hour range properly based on the 12/24 hour display mode. configurePickerRanges(); // initialize to current time Calendar cal = Calendar.GetInstance(ULocale.English); setOnTimeChangedListener(NO_OP_CHANGE_LISTENER); // by default we're not in 24 hour mode setCurrentHour(cal.Get(CalendarField.HourOfDay)); setCurrentMinute(cal.Get(CalendarField.Minute)); setCurrentSecond(cal.Get(CalendarField.Second)); mIsAm = (mCurrentHour < 12); /* Get the localized am/pm strings and use them in the spinner */ DateFormatSymbols dfs = new DateFormatSymbols(); string[] dfsAmPm = dfs.GetAmPmStrings(); mAmText = dfsAmPm[Calendar.Am]; mPmText = dfsAmPm[Calendar.Pm]; mAmPmButton.SetText(mIsAm ? mAmText : mPmText, TextView.BufferType.Normal); mAmPmButton.SetOnClickListener(new OnClickListener() { Clicked = (View v) => { //requestFocus(); if (mIsAm) { // Currently AM switching to PM if (mCurrentHour < 12) { mCurrentHour += 12; } } else { // Currently PM switching to AM if (mCurrentHour >= 12) { mCurrentHour -= 12; } } mIsAm = !mIsAm; mAmPmButton.SetText(mIsAm ? mAmText : mPmText, TextView.BufferType.Normal); onTimeChanged(); } }); SetEnabled(); }
public TimeSpanPickerDialog(Context context, EventHandler <TimeSpan> callback, TimeSpan time, TimeSpan minTime, TimeSpan maxTime) : base(context) { _callback = callback; _minTime = minTime; _maxTime = maxTime; SetCancelable(true); SetCanceledOnTouchOutside(true); SetButton((int)DialogButtonType.Negative, "Cancel", OnCancelClicked); SetButton((int)DialogButtonType.Positive, "OK", OnOkClicked); var dialogContent = new LinearLayout(Context); dialogContent.SetHorizontalGravity(global::Android.Views.GravityFlags.Center); dialogContent.SetVerticalGravity(global::Android.Views.GravityFlags.Center); dialogContent.SetPadding(20, 20, 20, 0); var numberFormatter = new NumberPickerFormatter(); _hoursPicker = new NumberPicker(Context) { MinValue = 0, MaxValue = 23, WrapSelectorWheel = false, }; _hoursPicker.Value = time.Hours; _hoursPicker.ValueChanged += HourPicker_ValueChanged; _hoursPicker.SetFormatter(numberFormatter); _minutesPicker = new NumberPicker(Context) { MinValue = 0, MaxValue = 59, WrapSelectorWheel = false, }; _minutesPicker.Value = time.Minutes; _minutesPicker.ValueChanged += MinutePicker_ValueChanged; _minutesPicker.SetFormatter(numberFormatter); _secondsPicker = new NumberPicker(Context) { MinValue = 0, MaxValue = 59, WrapSelectorWheel = false, }; _secondsPicker.Value = time.Seconds; _secondsPicker.SetFormatter(numberFormatter); dialogContent.AddView(_hoursPicker); dialogContent.AddView(new TextView(Context) { Text = ":" }); dialogContent.AddView(_minutesPicker); dialogContent.AddView(new TextView(Context) { Text = ":" }); dialogContent.AddView(_secondsPicker); UpdateHoursPickerConstraints(); UpdateMinutesPickerConstraints(); UpdateSecondsPickerConstraints(); SetView(dialogContent); }
//--------------------------------------------------------------------------------------------------------------------------------------------------- //Adding a new product. private void ListForChoosingAlcohols_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { //Creating a new layout for entering a number of grams. AlertDialog.Builder Object = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.From(this); LinearLayout layout = new LinearLayout(this); View alcohol_Quantity = inflater.Inflate(Resource.Layout.alcohol_Quantity, layout); Object.SetView(alcohol_Quantity); //Elements from the layout. NumberPicker AlcoholAmount = alcohol_Quantity.FindViewById <NumberPicker>(Resource.Id.AmountPicker); AlcoholAmount.MinValue = 1; AlcoholAmount.MaxValue = 1000; //Setting a formatter to a number picker. AlcoholAmount.SetFormatter(new HelpclassNumberPickerFormatter()); //Action on pressing positive button. Object.SetPositiveButton(Resource.String.OK, new EventHandler <DialogClickEventArgs>(delegate(object Sender, DialogClickEventArgs e1) { //Creating a new product and adding it to the user's list of products. Alcohol TempAlcohol = DatabaseAlcohol.GetAlcohol(ListForAlcohols.ElementAt(e.Position)); TempAlcohol.Setter(AlcoholAmount.Value * 10, DateTime.Now); User TempUser = DatabaseUser.GetUser(User.CurrentUser); TempUser.Alcohols.Add(TempAlcohol); DatabaseUser.SQConnection.UpdateWithChildren(TempUser); //Variables for counting alcohol parameters. double amountOfAlcohol = 0; String forAmountOfAlcohol = ""; String forWarning = ""; //If there is no info about weight of the user. if (DatabaseUser.GetUser(User.CurrentUser).Parameters.Count == 0) { forAmountOfAlcohol = Resources.GetString(Resource.String.MessageAlcohol_NoWeightInfo); } //If there is info, counting. else { //For each alcohol of the user. foreach (Alcohol Temp in DatabaseUser.GetUser(User.CurrentUser).Alcohols) { //If the date matches the choosed date. if ((DateTime.Now.DayOfYear - Temp.Date.DayOfYear) <= 1) { //Counting the amount of alcohol in blood. double dodamountOfAlcohol = 0; double coef; if (DatabaseUser.GetUser(User.CurrentUser).Sex == ENSex.Male) { coef = 0.68; } else { coef = 0.55; } TimeSpan X = DateTime.Now - Temp.Date; dodamountOfAlcohol = Math.Round((Temp.PercentageOfAlchol / (DatabaseUser.GetUser(User.CurrentUser).Parameters.Last().Weight *coef) - (X.Hours * 0.1)), 2); if (dodamountOfAlcohol > 0) { amountOfAlcohol += dodamountOfAlcohol; } } //Setting the amount of alcohol to the string. forAmountOfAlcohol = Resources.GetString(Resource.String.MessageGeneral_YouHave) + " " + amountOfAlcohol + " " + Resources.GetString(Resource.String.MessageAlcohol_ppmOfAlcohol); } //If it's bigger than can be according to the licence and the user has a licence. if (DatabaseUser.GetUser(User.CurrentUser).DrivingLicence == true && (DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Ukraine && amountOfAlcohol > 0.2 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Russia && amountOfAlcohol > 0.35 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Albania && amountOfAlcohol > 0.1 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Andorra && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Armenia && amountOfAlcohol > 0 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Austria && amountOfAlcohol > 0.49 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Azerbaijan && amountOfAlcohol > 0.29 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Belarus && amountOfAlcohol > 0.3 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Belgium && amountOfAlcohol > 0.49 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.BosniaAndHerzegovina && amountOfAlcohol > 0.3 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Bulgaria && amountOfAlcohol > 0.49 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Croatia && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Cyprus && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.CzechRepublic && amountOfAlcohol > 0 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Denmark && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Estonia && amountOfAlcohol > 0.2 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Finland && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.France && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Georgia && amountOfAlcohol > 0.3 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Germany && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Greece && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Hungary && amountOfAlcohol > 0 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Iceland && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Ireland && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Italy && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Latvia && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Liechtenstein && amountOfAlcohol > 0.8 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Lithuania && amountOfAlcohol > 0.4 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Luxembourg && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Macedonia && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Malta && amountOfAlcohol > 0.8 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Moldova && amountOfAlcohol > 0 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Montenegro && amountOfAlcohol > 0.3 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Netherlands && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Norway && amountOfAlcohol > 0.2 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Poland && amountOfAlcohol > 0.2 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Portugal && amountOfAlcohol > 0.49 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Romania && amountOfAlcohol > 0 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Serbia && amountOfAlcohol > 0.3 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Slovakia && amountOfAlcohol > 0 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Slovenia && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Spain && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Sweden && amountOfAlcohol > 0.2 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Switzerland && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.Turkey && amountOfAlcohol > 0.5 || DatabaseUser.GetUser(User.CurrentUser).Country == ENCountry.UK && amountOfAlcohol > 0.8)) { forWarning = Resources.GetString(Resource.String.MessageAlcohol_WarningAlcohol) + " " + DatabaseUser.GetUser(User.CurrentUser).Country + ". " + Resources.GetString(Resource.String.MessageAlcohol_WarningAlcoholTime) + " " + Math.Ceiling(amountOfAlcohol / 1.15) + " " + Resources.GetString(Resource.String.other_Hours) + " "; } //If the amount of alcohol is too big. if (amountOfAlcohol >= 3.5) { forWarning += Resources.GetString(Resource.String.MessageAlcohol_WarningAlcoholDeath); } } //Showing warnings. View view = inflater.Inflate(Resource.Layout.message_AlcoholWarnings, null); var TextForLevel = view.FindViewById <TextView>(Resource.Id.TextForLevel); var TextForWarning = view.FindViewById <TextView>(Resource.Id.TextForWarning); TextForLevel.Text = forAmountOfAlcohol; TextForWarning.Text = forWarning; var toast = new Toast(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity) { Duration = ToastLength.Long, View = view }; toast.Show(); })); //Action on pressing negative button. Object.SetNegativeButton(Resource.String.Cancel, new EventHandler <DialogClickEventArgs>(delegate(object Sender, DialogClickEventArgs e1){})); //Showing the form. Object.Show(); }