protected override void OnBindDialogView(View view)
        {
            base.OnBindDialogView(view);

            var currentValue = GetPersistedInt(SettingsScreen.DefaultRadiusValue);

            if (BuildVersionCodes.Honeycomb > Build.VERSION.SdkInt)
            {
                _radioGroup = (RadioGroup)view;
                foreach (var distance in Constants.AlarmRadiusValues)
                {
                    var radioButton = new RadioButton(Context);
                    radioButton.SetText(string.Format(Context.GetString(Resource.String.settings_default_radius_sum), distance), TextView.BufferType.Normal);
                    radioButton.Checked = distance == currentValue;
                    radioButton.Id = distance;
                    _radioGroup.AddView(radioButton);
                }
            }
            else
            {
                _numberPicker = (NumberPicker)view;
                SetNumberPickerTextColor(_numberPicker, Context.Resources.GetColor(Resource.Color.dark));
                _numberPicker.DescendantFocusability = DescendantFocusability.BlockDescendants;
                _numberPicker.SetDisplayedValues(Constants.AlarmRadiusValues.Select(v => v.ToString()).ToArray());
                _numberPicker.MinValue = 0;
                _numberPicker.MaxValue = Constants.AlarmRadiusValues.Count() - 1;
                _numberPicker.WrapSelectorWheel = false;
                _numberPicker.Value = Constants.AlarmRadiusValues.IndexOf(currentValue);
            }
        }
        protected void InitRadioButtons(string[,] aLaunchExtensions, string aUrl, string aResourceID, RadioGroup aRadioGroup)
        {
            aRadioGroup.RemoveAllViews();

            SortedList<int, RadioButton> _myList = new SortedList<int, RadioButton>();

            for (int i = 0; i < aLaunchExtensions.GetLength(0); i++)
            {
                string _curS = aLaunchExtensions[i, 0];
                string _curParam = aLaunchExtensions[i, 1];

                RadioButton _button = new RadioButton(this);
                _button.Text = string.Format("{0} [{1}]",_curS,_curParam);
                _button.Tag = i;

                string _resourceName = aResourceID + _curParam;
                if (_resourceName == aResourceID)
                { _resourceName = aResourceID+"nothing"; };

                // int _resourceID = Resources.GetIdentifier(_resourceName, "drawable", this.PackageName);
                if (_resourceName != "nothing")
                {
                    try
                    {
                        var _resourceID = (int)typeof(Resource.Drawable).GetField(_resourceName).GetValue(null);
                        if (_resourceID > 0)
                        {
                            Android.Graphics.Drawables.Drawable _d = Resources.GetDrawable(_resourceID);
                            _d.SetBounds(0, 0, 120, 120);
                            _button.SetCompoundDrawables(_d, null, null, null);
                        };
                    }
                    catch { };
                };
                aRadioGroup.AddView(_button);

                if ((aUrl.IndexOf(_curParam) >= 0) && (_curParam != ""))
                {
                    _myList.Add(_curParam.Length, _button);
                };
            };

            if (_myList.Count > 0)
            {
                RadioButton _button = _myList.Values[_myList.Count() - 1];
                aRadioGroup.Check(_button.Id);
            };
        }
        private void InitComponents()
        {
            this.Title = "Live Survey";
            var txtQuestion = FindViewById<TextView>(Resource.Id.txtLiveQuestion);

            txtQuestion.Text = VM.CurrentQuestion.QuestionText;
            if (VM.CurrentQuestion.IsMultiSelect)
            {
                foreach (var opt in VM.CurrentQuestion.Options)
                {
                    var button = new CheckBox(this);
                    button.Text = opt.OptionText;
                    button.Checked = opt.IsSelected;
                    button.Id = opt.Id;
                    button.CheckedChange += button_CheckedChange;
                    layout.AddView(button);
                }
            }
            else
            {
                radioGroup = new RadioGroup(this);
                foreach (var opt in VM.CurrentQuestion.Options)
                {
                    var button = new RadioButton(this);
                    button.Text = opt.OptionText;
                    button.Checked = opt.IsSelected;
                    button.Id = opt.Id;
                    radioGroup.AddView(button);

                }
                layout.AddView(radioGroup);
                radioGroup.CheckedChange += radioGroup_CheckedChange;

            }
        }
Example #4
0
      protected override View OnCreateDialogView()
      {
         
         LayoutInflater inflator = LayoutInflater.FromContext(this.Context);
         View dialog = inflator.Inflate(Resource.Layout.opencl_preference, null);

         _openCLRadioGroup = dialog.FindViewById<RadioGroup>(Resource.Id.opencl_preference_radio_group);

         AppPreference preference = new AppPreference();

         RadioButton checkedButton = null;
         RadioButton cpuButton = new RadioButton(this.Context);
         cpuButton.Text = "CPU";

         _openCLRadioGroup.AddView(cpuButton);
         //int selectedIdx = -1;
         if (preference.UseOpenCL == false)
         {
            checkedButton = cpuButton;
         }
         cpuButton.Click += (sender, args) =>
         {
            preference.UseOpenCL = false;
            //Toast.MakeText(this.Context, "cpu clicked", ToastLength.Short).Show();
         };

         String selectedDeviceName = preference.OpenClDeviceName;
         if (selectedDeviceName == null && CvInvoke.HaveOpenCL && preference.UseOpenCL)
         {
            selectedDeviceName = OclDevice.Default.Name;
         }
         //int counter = 1;
         using (VectorOfOclPlatformInfo oclPlatformInfos = OclInvoke.GetPlatformsInfo())
         {
            if (oclPlatformInfos.Size > 0)
            {
               for (int i = 0; i < oclPlatformInfos.Size; i++)
               {
                  OclPlatformInfo platformInfo = oclPlatformInfos[i];

                  for (int j = 0; j < platformInfo.DeviceNumber; j++)
                  {
                     OclDevice device = platformInfo.GetDevice(j);
                     RadioButton deviceButton = new RadioButton(this.Context);
                     deviceButton.Text = "OpenCL: " + device.Name;

                     if (preference.UseOpenCL == true && device.Name.Equals(selectedDeviceName))
                     {
                        checkedButton = deviceButton;
                     }
                     _openCLRadioGroup.AddView(deviceButton);

                     //counter++;
                     deviceButton.Click += (sender, args) =>
                     {
                        preference.UseOpenCL = true;
                        preference.OpenClDeviceName = device.Name;
                        //Toast.MakeText(this.Context, device.Name + " clicked", ToastLength.Short).Show();
                     };

                  }
               }
            }
         }
         if (checkedButton != null)
            _openCLRadioGroup.Check(checkedButton.Id);
         //_openCLRadioGroup.in
         /*
            _openCLToggleButton.Checked = preference.UseOpenCL;

            _openCLToggleButton.CheckedChange += (sender, args) =>
            {
               bool isChecked = args.IsChecked;

               if (isChecked && !CvInvoke.HaveOpenCL)
               {
                  _openCLToggleButton.Checked = false;
                  Toast.MakeText(Context, "No OpenCL compatible device found.", ToastLength.Long).Show();
                  isChecked = false;
               }

               preference.UseOpenCL = isChecked;
            };
            */
         return dialog;
      }
		public Task<int?> ChooseSingleAsync(string message, string[] options, int? chosenItem, string title = null, string okButton = "OK", string cancelButton = "Cancel", TimeSpan? duration = null)
		{
			var tcs = new TaskCompletionSource<int?>();

			Application.SynchronizationContext.Post(ignored =>
			{
				if (this.CurrentActivity == null)
					return;

				var radioButtons = options
					.Select((option, i) =>
					{
						var checkBox = new RadioButton(this.CurrentActivity)
						{
							LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
							{
								Gravity = GravityFlags.CenterVertical
							},

							Id = (i + 1),
							Text = option,
							Gravity = GravityFlags.Center,
						};

						checkBox.SetTextColor(Color.White);

						return checkBox;
					})
					.ToArray();

				var radioGroup = new RadioGroup(this.CurrentActivity)
				{
					LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent),
					Orientation = Orientation.Vertical
				};

				foreach (var optionLayout in radioButtons)
				{
					radioGroup.AddView(optionLayout);
				}

				var scrollView = new ScrollView(this.CurrentActivity)
				{
					LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent),
				};

				scrollView.AddView(radioGroup);

				var builder = new AlertDialog.Builder(this.CurrentActivity)
					.SetMessage(message)
					.SetTitle(title)
					.SetView(scrollView)
					.SetPositiveButton(okButton, delegate
					{
						tcs.TrySetResult((radioGroup.CheckedRadioButtonId > 0) ? (radioGroup.CheckedRadioButtonId - 1) : ((int?)null));
					})
					.SetNegativeButton(cancelButton, delegate
					{
						tcs.TrySetResult(null);
					});

				var dialog = this.CustomizeAndCreate(builder);
				dialog.Show();

				if (duration.HasValue)
					Task.Delay(duration.Value).ContinueWith((delayTask) => Application.SynchronizationContext.Post(ignored2 => dialog.SafeDismiss(), null));
			}, null);

			return tcs.Task;
		}
Example #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            // Create your application here
            var voteString = Intent.GetStringExtra ("vote");
            SelectedVote = Newtonsoft.Json.JsonConvert.DeserializeObject<Vote> (voteString);

            SelectedIndexes = new Dictionary<int, bool> ();

            SetContentView (Resource.Layout.votenowview);

            LinearLayout currentLayout = FindViewById <LinearLayout>(Resource.Id.votenow_content);

            if (SelectedVote.SelectType == AnswerType.Single) {

                RadioGroup radioG = new RadioGroup (this);

                LinearLayout.LayoutParams radioGP = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                LinearLayout.LayoutParams rlp = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

                foreach (var answer in SelectedVote.Answers) {

                    var button = new RadioButton (this);
                    button.Id = answer.Id;
                    button.Text = $"{answer.Title}:{answer.Description}";

                    radioG.AddView (button, rlp);
                }

                radioG.CheckedChange += (object sender, RadioGroup.CheckedChangeEventArgs e) => {

                    if (!SelectedIndexes.Keys.Contains (e.CheckedId)) {
                        SelectedIndexes.Add (e.CheckedId, true);
                    }

                };

                currentLayout.AddView (radioG, radioGP);

            }
            else {

                LinearLayout.LayoutParams rlp = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

                foreach (var answer in SelectedVote.Answers) {

                    var button = new CheckBox (this);
                    button.Id = answer.Id;
                    button.Text = $"{answer.Title}:{answer.Description}";

                    currentLayout.AddView (button, rlp);

                    button.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {

                        var btn = sender as CheckBox;

                        if (!SelectedIndexes.Keys.Contains ( btn.Id )) {
                            SelectedIndexes.Add ( btn.Id, true);
                        }
                    };
                }

            }

            var btnConfirm = FindViewById<Button> (Resource.Id.votenowview_btnConfirm);
            btnConfirm.Click += (sender, e) => {

                SelectedVote.Answers.ForEach (answer => { if (SelectedIndexes.Keys.Contains (answer.Id)) { answer.Count++; } } );

                var nowVoteString = Newtonsoft.Json.JsonConvert.SerializeObject (SelectedVote);

                Intent voteResultView = new Intent (this, typeof (VoteResultActivity));
                voteResultView.PutExtra ("vote", nowVoteString);
                StartActivity (voteResultView);

            };
        }