public override View GetView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.From(dialog.Context).Inflate(layout, parent, false); } TextView tv = convertView.FindViewById <TextView>(Resource.Id.title); switch (dialog.ListType) { case ListType.Single: { RadioButton radio = convertView.FindViewById <RadioButton>(Resource.Id.control); bool selected = dialog.MBuilder.SelectedIndex == position; MDTintHelper.SetTint(radio, dialog.MBuilder.WidgetColor); radio.Checked = selected; if (selected && InitRadio) { RadioButton = radio; } } break; case ListType.Multi: { CheckBox checkbox = convertView.FindViewById <CheckBox>(Resource.Id.control); bool selected = dialog.SelectedIndicesList.Contains(position); MDTintHelper.SetTint(checkbox, dialog.MBuilder.WidgetColor); checkbox.Checked = selected; } break; } tv.Text = dialog.MBuilder.Items[position]; tv.SetTextColor(dialog.MBuilder.ItemColor); dialog.SetTypeface(tv, dialog.MBuilder.RegularFont); convertView.Tag = position + ":" + dialog.MBuilder.Items[position]; SetupGravity((ViewGroup)convertView); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { ViewGroup group = (ViewGroup)convertView; if (group.ChildCount == 2) { if (group.GetChildAt(0) is CompoundButton) { group.GetChildAt(0).Background = null; } else if (group.GetChildAt(1) is CompoundButton) { group.GetChildAt(1).Background = null; } } } return(convertView); }
private static void SetupInputDialog(MaterialDialog dialog) { MaterialDialog.Builder builder = dialog.MBuilder; dialog.Input = dialog.GetView().FindViewById <EditText>(Android.Resource.Id.Input); if (dialog.Input == null) { return; } dialog.SetTypeface(dialog.Input, builder.RegularFont); if (builder.InputPrefill != null) { dialog.Input.Text = builder.InputPrefill; } dialog.SetInternalInputCallback(); dialog.Input.Hint = builder.InputHint; dialog.Input.SetSingleLine(); dialog.Input.SetTextColor(builder.ContentColor); dialog.Input.SetHintTextColor(DialogUtils.AdjustAlpha(builder.ContentColor, 0.3f)); MDTintHelper.SetTint(dialog.Input, dialog.MBuilder.WidgetColor); if (builder.InputType != Android.Text.InputTypes.Null) { dialog.Input.InputType = builder.InputType; if ((builder.InputType & Android.Text.InputTypes.TextVariationPassword) == Android.Text.InputTypes.TextVariationPassword) { dialog.Input.TransformationMethod = PasswordTransformationMethod.Instance; } } dialog.InputMinMax = dialog.GetView().FindViewById <TextView>(Resource.Id.minMax); if (builder.InputMaxLength > -1) { dialog.InvalidateInputMinMaxIndicator(dialog.Input.Text.Length, !builder.InputAllowEmpty); } else { dialog.InputMinMax.Visibility = ViewStates.Gone; dialog.InputMinMax = null; } }
public void ShowCustomView(object sender, EventArgs e) { MaterialDialog dialog = new MaterialDialog.Builder(this) .Title(Resource.String.googleWifi) .CustomView(Resource.Layout.dialog_customview, true) .PositiveText(Resource.String.connect) .NegativeText(Android.Resource.String.Cancel) .OnPositive((dialog1, which) => ShowToast("Password: " + _passwordInput.Text)) .Build(); _positiveAction = dialog.GetActionButton(DialogAction.Positive); _passwordInput = dialog.CustomView.FindViewById <EditText>(Resource.Id.password); _passwordInput.TextChanged += (s, ev) => { _positiveAction.Enabled = String.Concat(ev.Text.Select(c => c.ToString())).Trim().Length > 0; }; CheckBox checkbox = dialog.CustomView.FindViewById <CheckBox>(Resource.Id.showPassword); checkbox.CheckedChange += (s, ev) => { _passwordInput.InputType = (!ev.IsChecked) ? InputTypes.TextVariationPassword : InputTypes.ClassText; _passwordInput.TransformationMethod = (!ev.IsChecked) ? PasswordTransformationMethod.Instance : null; }; int widgetColor = ThemeSingleton.Get().WidgetColor; MDTintHelper.SetTint(checkbox, widgetColor == 0 ? ContextCompat.GetColor(this, Resource.Color.accent) : widgetColor); MDTintHelper.SetTint(_passwordInput, widgetColor == 0 ? ContextCompat.GetColor(this, Resource.Color.accent) : widgetColor); dialog.Show(); _positiveAction.Enabled = false; }
private static void SetupProgressDialog(MaterialDialog dialog) { MaterialDialog.Builder builder = dialog.MBuilder; if (builder.IndeterminateProgress || builder.Progress > -2) { dialog.Progress = dialog.GetView().FindViewById <ProgressBar>(Android.Resource.Id.Progress); if (dialog.Progress == null) { return; } if (builder.IndeterminateProgress && !builder.IndeterminateIsHorizontalProgress && Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich && Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { dialog.Progress.IndeterminateDrawable = new CircularProgressDrawable( builder.WidgetColor, builder.Context.Resources.GetDimension(Resource.Dimension.circular_progress_border)); MDTintHelper.SetTint(dialog.Progress, builder.WidgetColor, true); } else { MDTintHelper.SetTint(dialog.Progress, builder.WidgetColor); } if (!builder.IndeterminateProgress || builder.IndeterminateIsHorizontalProgress) { dialog.Progress.Indeterminate = builder.IndeterminateIsHorizontalProgress; dialog.Progress.Progress = 0; dialog.Progress.Max = builder.ProgressMax; dialog.ProgressLabel = dialog.GetView().FindViewById <TextView>(Resource.Id.label); if (dialog.ProgressLabel != null) { dialog.ProgressLabel.SetTextColor(builder.ContentColor); dialog.SetTypeface(dialog.ProgressLabel, builder.MediumFont); dialog.ProgressLabel.Text = String.Format(builder.ProgressPercentFormat, 0); } dialog.ProgressMinMax = dialog.GetView().FindViewById <TextView>(Resource.Id.minMax); if (dialog.ProgressMinMax != null) { dialog.ProgressMinMax.SetTextColor(builder.ContentColor); dialog.SetTypeface(dialog.ProgressMinMax, builder.RegularFont); if (builder.ShowMinMax) { dialog.ProgressMinMax.Visibility = ViewStates.Visible; dialog.ProgressMinMax.Text = String.Format(builder.ProgressNumberFormat, 0, builder.ProgressMax); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)dialog.Progress.LayoutParameters; lp.LeftMargin = 0; lp.RightMargin = 0; } else { dialog.ProgressMinMax.Visibility = ViewStates.Gone; } } else { builder.ShowMinMax = false; } } } }
protected override void ShowDialog(Bundle state) { var mBuilder = new MaterialDialog.Builder(Context) .SetTitle(DialogTitle) .SetIcon(DialogIcon) .SetPositiveText(PositiveButtonText) .SetNegativeText(NegativeButtonText) .SetDismissListener(this) .SetCallback(new ButtonCallback { Positive = (x) => { OnClick(x, (int)DialogButtonType.Positive); String value = mEditText.Text; if (CallChangeListener(value) && Persistent) { Text = value; } }, Neutral = (x) => { OnClick(x, (int)DialogButtonType.Neutral); }, Negative = (x) => { OnClick(x, (int)DialogButtonType.Negative); } }) .SetDismissListener(this); View layout = LayoutInflater.From(Context).Inflate(Resource.Layout.sino_droid_md_stub_inputpref, null); OnBindDialogView(layout); MDTintHelper.SetTint(mEditText, mColor); TextView message = layout.FindViewById <TextView>(Android.Resource.Id.Message); if (DialogMessage != null && DialogMessage.Length > 0) { message.Visibility = ViewStates.Visible; message.Text = DialogMessage; } else { message.Visibility = ViewStates.Gone; } mBuilder.SetCustomView(layout, false); try { var pm = PreferenceManager; Java.Lang.Reflect.Method method = pm.Class.GetDeclaredMethod( "registerOnActivityDestroyListener", Java.Lang.Class.FromType(typeof(PreferenceManager.IOnActivityDestroyListener))); method.Accessible = true; method.Invoke(pm, this); } catch (Exception) { } mDialog = mBuilder.Build(); if (state != null) { mDialog.OnRestoreInstanceState(state); } RequestInputMethod(mDialog); mDialog.Show(); }