void OnColorButtonSizeChanged(object sender, EventArgs args) { ColorButton cb = sender as ColorButton; var scale = (btnColor.Width / BTN_COLOR_WIDTH < btnColor.Height / BTN_COLOR_HEIGHT) ? btnColor.Width / BTN_COLOR_WIDTH : btnColor.Height / BTN_COLOR_HEIGHT; cb.WidthRequest = cb.size.Width * scale; cb.HeightRequest = cb.size.Height * scale; }
void OnColorButtonClicked(object sender, EventArgs args) { ColorButton cb = sender as ColorButton; color = cb.color; btnColor.Image = cb.colorPickerImage; isDirty = true; Analytics.TrackEventProfile(Analytics.EVENT_PPROFILE_COLOR); }
void InitLayout(bool showDeleteButton, bool isCreateMode) { // layout top imgButtonBack = new Image(); imgButtonBack.Source = "@drawable/btn_back.png"; tgrButtonBack = new TapGestureRecognizer(); tgrButtonBack.Tapped += OnButtonBackTapped; imgButtonBack.GestureRecognizers.Add(tgrButtonBack); layout.Children.Add ( imgButtonBack, Constraint.RelativeToParent(parent => parent.Width * 0.036), Constraint.RelativeToParent(parent => parent.Height * 0.022) ); lblCaption = new CustomLabel(); lblCaption.Size = CustomLabel.SIZE_CAPTION; lblCaption.TextColor = Color.FromHex("4D4C4A"); if (isCreateMode) { lblCaption.Text = Localization.pageProfileEditCreate; // create profile } else { lblCaption.Text = Localization.pageProfileEditHead; // edit profile } layout.Children.Add ( lblCaption, Constraint.RelativeToParent(parent => parent.Width * 0.5 - lblCaption.Width * 0.5), Constraint.RelativeToParent(parent => parent.Height * 0.03) ); imgButtonHelp = new Image(); imgButtonHelp.Source = "@drawable/btn_help_profile.png"; tgrButtonHelp = new TapGestureRecognizer(); tgrButtonHelp.Tapped += OnButtonHelpTapped; imgButtonHelp.GestureRecognizers.Add(tgrButtonHelp); layout.Children.Add ( imgButtonHelp, Constraint.RelativeToParent(parent => parent.Width * 0.81), Constraint.RelativeToParent(parent => parent.Height * 0.022) ); // layout middle btnCalibration = new Button(); btnCalibration.Image = Localization.btn_profile_calibration; btnCalibration.BackgroundColor = Color.Transparent; btnCalibration.Clicked += OnButtonCalibration; layout.Children.Add ( btnCalibration, Constraint.RelativeToParent((parent) => parent.Width * 0.5 - btnCalibration.Width * 0.5), Constraint.RelativeToParent((parent) => parent.Height * 0.23 - btnCalibration.Height * 0.5) ); btnVehicle = new Button(); btnVehicle.Image = Localization.btn_profile_vehicle; btnVehicle.BackgroundColor = Color.Transparent; btnVehicle.Clicked += OnButtonVehicle; layout.Children.Add ( btnVehicle, Constraint.RelativeToParent((parent) => parent.Width * 0.5 - btnVehicle.Width * 0.5), Constraint.RelativeToParent((parent) => parent.Height * 0.36 - btnVehicle.Height * 0.5) ); entryVehicle = new CustomEntry(); entryVehicle.IsVisible = false; entryVehicle.BackgroundColor = Color.Black; entryVehicle.FontSize *= 2; entryVehicle.SizeChanged += OnLayoutSizeChanged; // width of layout is not known on page create -> delegate setup of entry.width to callback entryVehicle.Completed += OnEntryVehicleComplete; entryVehicle.Unfocused += OnEntryVehicleComplete; layout.Children.Add ( entryVehicle, Constraint.RelativeToView(btnVehicle, (parent, view) => (view.X + view.Width * 0.5 - entryVehicle.Width * 0.5)), Constraint.RelativeToView(btnVehicle, (parent, view) => (view.Y + view.Height * 0.5 - entryVehicle.Height * 0.5)) ); btnColor = new Button(); btnColor.IsEnabled = false; btnColor.Image = GetColorPickerImageFromItem(item); btnColor.BackgroundColor = Color.Transparent; layout.Children.Add ( btnColor, Constraint.RelativeToParent((parent) => parent.Width * 0.5 - btnColor.Width * 0.5), Constraint.RelativeToParent((parent) => parent.Height * 0.62 - btnColor.Height * 0.5) ); for (int i = 0; i < colorButtons.Length; i++) { ColorButton b = colorButtons[i]; b.SizeChanged += OnColorButtonSizeChanged; b.Clicked += OnColorButtonClicked; layout.Children.Add ( b, Constraint.RelativeToView(btnColor, (parent, view) => (view.X + b.position.X * ((view.Width / BTN_COLOR_WIDTH < view.Height / BTN_COLOR_HEIGHT) ? view.Width / BTN_COLOR_WIDTH : view.Height / BTN_COLOR_HEIGHT))), Constraint.RelativeToView(btnColor, (parent, view) => (view.Y + b.position.Y * ((view.Width / BTN_COLOR_WIDTH < view.Height / BTN_COLOR_HEIGHT) ? view.Width / BTN_COLOR_WIDTH : view.Height / BTN_COLOR_HEIGHT))) ); } // layout bottom if (showDeleteButton) { btnDelete = new Button(); btnDelete.Image = Localization.btn_profile_delete; btnDelete.BackgroundColor = Color.Transparent; btnDelete.Clicked += OnButtonDelete; layout.Children.Add ( btnDelete, Constraint.RelativeToParent((parent) => parent.Width / 2 - btnDelete.Width / 2), Constraint.RelativeToParent((parent) => parent.Height - btnDelete.Height) ); } }