protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.activity_main); Cheeseknife.Bind(this); _handler = new Handler(); _primaryPreselect = DialogUtils.ResolveColor(this, Resource.Attribute.colorPrimary); _accentPreselect = DialogUtils.ResolveColor(this, Resource.Attribute.colorAccent); }
private static ColorStateList CreateEditTextColorStateList(Context context, Color color) { int[][] states = new int[3][]; int[] colors = new int[3]; int i = 0; states[i] = new int[] { -Android.Resource.Attribute.StateEnabled }; colors[i] = DialogUtils.ResolveColor(context, Resource.Attribute.colorControlNormal); i++; states[i] = new int[] { -Android.Resource.Attribute.StatePressed, -Android.Resource.Attribute.StateFocused }; colors[i] = DialogUtils.ResolveColor(context, Resource.Attribute.colorControlNormal); i++; states[i] = new int[] { }; colors[i] = color; return(new ColorStateList(states, colors)); }
private void Init(Context context, IAttributeSet attrs, int defStyleAttr) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.MDRootLayout, defStyleAttr, 0); mReducePaddingNoTitleNoButtons = a.GetBoolean(Resource.Styleable.MDRootLayout_sino_droid_md_reduce_padding_no_title_no_buttons, true); a.Recycle(); mNoTitlePaddingFull = context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_notitle_vertical_padding); mButtonPaddingFull = context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_button_frame_vertical_padding); mButtonHorizontalEdgeMargin = context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_button_padding_frame_side); mButtonBarHeight = context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_button_height); mDividerPaint = new Paint(); mDividerWidth = context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_divider_height); mDividerPaint.Color = DialogUtils.ResolveColor(context, Resource.Attribute.sino_droid_md_divider_color); SetWillNotDraw(false); }
public static void SetTint(RadioButton radioButton, Color color) { ColorStateList sl = new ColorStateList(new int[][] { new int[] { -Android.Resource.Attribute.StateChecked }, new int[] { Android.Resource.Attribute.StateChecked } } , new int[] { DialogUtils.ResolveColor(radioButton.Context, Resource.Attribute.colorControlNormal), color }); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { radioButton.ButtonTintList = sl; } else { Drawable d = ContextCompat.GetDrawable(radioButton.Context, Resource.Drawable.abc_btn_radio_material); DrawableCompat.SetTintList(d, sl); radioButton.SetButtonDrawable(d); } }
public MaterialEditTextPreference(Context context, IAttributeSet attrs) : base(context, attrs) { int fallback; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { fallback = DialogUtils.ResolveColor(context, Android.Resource.Attribute.ColorAccent); } else { fallback = 0; } fallback = DialogUtils.ResolveColor(context, Resource.Attribute.colorAccent, fallback); mColor = DialogUtils.ResolveColor(context, Resource.Attribute.sino_droid_md_widget_color, fallback); mEditText = new AppCompatEditText(context, attrs); mEditText.Id = Android.Resource.Id.Edit; mEditText.Enabled = true; }
public static void Init(MaterialDialog dialog) { MaterialDialog.Builder builder = dialog.MBuilder; dialog.SetCancelable(builder.Cancelable); dialog.SetCanceledOnTouchOutside(builder.Cancelable); if (builder.BackgroundColor == 0) { builder.BackgroundColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_background_color); } if (builder.BackgroundColor != 0) { GradientDrawable drawable = new GradientDrawable(); drawable.SetCornerRadius(builder.Context.Resources.GetDimension(Resource.Dimension.sino_droid_md_bg_corner_radius)); drawable.SetColor(builder.BackgroundColor); DialogUtils.SetBackgroundCompat(dialog.GetView(), drawable); } if (!builder.PositiveColorSet) { builder.PositiveColor = DialogUtils.ResolveActionTextColorStateList(builder.Context, Resource.Attribute.sino_droid_md_positive_color, builder.PositiveColor); } if (!builder.NeutralColorSet) { builder.NeutralColor = DialogUtils.ResolveActionTextColorStateList(builder.Context, Resource.Attribute.sino_droid_md_neutral_color, builder.NeutralColor); } if (!builder.NegativeColorSet) { builder.NegativeColor = DialogUtils.ResolveActionTextColorStateList(builder.Context, Resource.Attribute.sino_droid_md_negative_color, builder.NegativeColor); } if (!builder.WidgetColorSet) { builder.WidgetColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_widget_color, builder.WidgetColor); } if (!builder.TitleColorSet) { int titleColorFallback = DialogUtils.ResolveColor(dialog.Context, Android.Resource.Attribute.TextColorPrimary); builder.TitleColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_title_color, titleColorFallback); } if (!builder.ContentColorSet) { int contentColorFallback = DialogUtils.ResolveColor(dialog.Context, Android.Resource.Attribute.TextColorSecondary); builder.ContentColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_content_color, contentColorFallback); } if (!builder.ItemColorSet) { builder.ItemColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_item_color, builder.ContentColor); } dialog.Title = dialog.GetView().FindViewById <TextView>(Resource.Id.title); dialog.Icon = dialog.GetView().FindViewById <ImageView>(Resource.Id.icon); dialog.TitleFrame = dialog.GetView().FindViewById(Resource.Id.titleFrame); dialog.Content = dialog.GetView().FindViewById <TextView>(Resource.Id.content); dialog.ListView = dialog.GetView().FindViewById <ListView>(Resource.Id.contentListView); dialog.PositiveButton = dialog.GetView().FindViewById <MDButton>(Resource.Id.buttonDefaultPositive); dialog.NeutralButton = dialog.GetView().FindViewById <MDButton>(Resource.Id.buttonDefaultNeutral); dialog.NegativeButton = dialog.GetView().FindViewById <MDButton>(Resource.Id.buttonDefaultNegative); if (builder.InputCallback != null && builder.PositiveText == null) { builder.PositiveText = builder.Context.GetText(Android.Resource.String.Ok); } dialog.PositiveButton.Visibility = builder.PositiveText != null ? ViewStates.Visible : ViewStates.Gone; dialog.NeutralButton.Visibility = builder.NeutralText != null ? ViewStates.Visible : ViewStates.Gone; dialog.NegativeButton.Visibility = builder.NegativeText != null ? ViewStates.Visible : ViewStates.Gone; if (builder.Icon != null) { dialog.Icon.Visibility = ViewStates.Visible; dialog.Icon.SetImageDrawable(builder.Icon); } else { Drawable d = DialogUtils.ResolveDrawable(builder.Context, Resource.Attribute.sino_droid_md_icon); if (d != null) { dialog.Icon.Visibility = ViewStates.Visible; dialog.Icon.SetImageDrawable(d); } else { dialog.Icon.Visibility = ViewStates.Gone; } } int maxIconSize = builder.MaxIconSize; if (maxIconSize == -1) { maxIconSize = DialogUtils.ResolveDimension(builder.Context, Resource.Attribute.sino_droid_md_icon_max_size); } if (builder.LimitIconToDefaultSize || DialogUtils.ResolveBoolean(builder.Context, Resource.Attribute.sino_droid_md_icon_limit_icon_to_default_size)) { maxIconSize = builder.Context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_icon_max_size); } if (maxIconSize > -1) { dialog.Icon.SetAdjustViewBounds(true); dialog.Icon.SetMaxHeight(maxIconSize); dialog.Icon.SetMaxWidth(maxIconSize); dialog.Icon.RequestLayout(); } if (!builder.DividerColorSet) { int dividerFallback = DialogUtils.ResolveColor(dialog.Context, Resource.Attribute.sino_droid_md_divider); builder.DividerColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_divider_color, dividerFallback); } dialog.GetView().SetDividerColor(new Color(builder.DividerColor)); if (dialog.Title != null) { dialog.SetTypeface(dialog.Title, builder.MediumFont); dialog.Title.SetTextColor(builder.TitleColor); dialog.Title.Gravity = GravityExt.GetGravity(builder.TitleGravity); if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1) { dialog.Title.TextAlignment = GravityExt.GetTextAlignment(builder.TitleGravity); } if (builder.Title == null) { dialog.TitleFrame.Visibility = ViewStates.Gone; } else { dialog.Title.Text = builder.Title; dialog.TitleFrame.Visibility = ViewStates.Visible; } } if (dialog.Content != null) { dialog.Content.MovementMethod = new LinkMovementMethod(); dialog.SetTypeface(dialog.Content, builder.RegularFont); dialog.Content.SetLineSpacing(0f, builder.ContentLineSpacingMultiplier); if (builder.PositiveColor == null) { dialog.Content.SetLinkTextColor(DialogUtils.ResolveColor(dialog.Context, Android.Resource.Attribute.TextColorPrimary)); } else { dialog.Content.SetLinkTextColor(builder.PositiveColor); } dialog.Content.SetTextColor(builder.ContentColor); dialog.Content.Gravity = GravityExt.GetGravity(builder.ContentGravity); if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1) { dialog.Content.TextAlignment = GravityExt.GetTextAlignment(builder.ContentGravity); } if (builder.Content != null) { dialog.Content.Text = builder.Content; dialog.Content.Visibility = ViewStates.Visible; } else { dialog.Content.Visibility = ViewStates.Gone; } } dialog.GetView().SetButtonGravity(builder.ButtonsGravity); dialog.GetView().SetButtonStackedGravity(builder.BtnStackedGravity); dialog.GetView().SetForceStack(builder.ForceStacking); bool textAllCaps; if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich) { textAllCaps = DialogUtils.ResolveBoolean(builder.Context, Android.Resource.Attribute.TextAllCaps, true); if (textAllCaps) { textAllCaps = DialogUtils.ResolveBoolean(builder.Context, Resource.Attribute.textAllCaps, true); } } else { textAllCaps = DialogUtils.ResolveBoolean(builder.Context, Resource.Attribute.textAllCaps, true); } MDButton positiveTextView = dialog.PositiveButton; dialog.SetTypeface(positiveTextView, builder.MediumFont); positiveTextView.SetAllCapsCompat(textAllCaps); positiveTextView.Text = builder.PositiveText; positiveTextView.SetTextColor(builder.PositiveColor); dialog.PositiveButton.SetStackedSelector(dialog.GetButtonSelector(DialogAction.Positive, true)); dialog.PositiveButton.SetDefaultSelector(dialog.GetButtonSelector(DialogAction.Positive, false)); dialog.PositiveButton.Tag = (int)DialogAction.Positive; dialog.PositiveButton.SetOnClickListener(dialog); dialog.PositiveButton.Visibility = ViewStates.Visible; MDButton negativeTextView = dialog.NegativeButton; dialog.SetTypeface(negativeTextView, builder.MediumFont); negativeTextView.SetAllCapsCompat(textAllCaps); negativeTextView.Text = builder.NegativeText; negativeTextView.SetTextColor(builder.NegativeColor); dialog.NegativeButton.SetStackedSelector(dialog.GetButtonSelector(DialogAction.Negative, true)); dialog.NegativeButton.SetDefaultSelector(dialog.GetButtonSelector(DialogAction.Negative, false)); dialog.NegativeButton.Tag = (int)DialogAction.Negative; dialog.NegativeButton.SetOnClickListener(dialog); dialog.NegativeButton.Visibility = ViewStates.Visible; MDButton neutralTextView = dialog.NeutralButton; dialog.SetTypeface(neutralTextView, builder.MediumFont); neutralTextView.SetAllCapsCompat(textAllCaps); neutralTextView.Text = builder.NeutralText; neutralTextView.SetTextColor(builder.NeutralColor); dialog.NeutralButton.SetStackedSelector(dialog.GetButtonSelector(DialogAction.Neutral, true)); dialog.NeutralButton.SetDefaultSelector(dialog.GetButtonSelector(DialogAction.Neutral, false)); dialog.NeutralButton.Tag = (int)DialogAction.Neutral; dialog.NeutralButton.SetOnClickListener(dialog); dialog.NeutralButton.Visibility = ViewStates.Visible; if (builder.ListCallbackMultiChoice != null) { dialog.SelectedIndicesList = new List <int>(); } if (dialog.ListView != null && (builder.Items != null && builder.Items.Length > 0 || builder.Adapter != null)) { dialog.ListView.Selector = dialog.GetListSelector(); if (builder.Adapter == null) { if (builder.ListCallbackSingleChoice != null) { dialog.ListType = ListType.Single; } else if (builder.ListCallbackMultiChoice != null) { dialog.ListType = ListType.Multi; if (builder.SelectedIndices != null) { dialog.SelectedIndicesList = builder.SelectedIndices.ToList(); } } else { dialog.ListType = ListType.Regular; } builder.Adapter = new MaterialDialogAdapter(dialog, ListTypeExt.GetLayoutForType(dialog.ListType)); } else if (builder.Adapter is MaterialSimpleListAdapter) { ((MaterialSimpleListAdapter)builder.Adapter).SetDialog(dialog, false); } } SetupProgressDialog(dialog); SetupInputDialog(dialog); if (builder.CustomView != null) { dialog.GetView().FindViewById <MDRootLayout>(Resource.Id.root).NoTitleNoPadding(); FrameLayout frame = dialog.GetView().FindViewById <FrameLayout>(Resource.Id.customViewFrame); dialog.CustomViewFrame = frame; View innerView = builder.CustomView; if (builder.WrapCustomViewInScroll) { var r = dialog.Context.Resources; int framePadding = r.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_dialog_frame_margin); ScrollView sv = new ScrollView(dialog.Context); int paddingTop = r.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_content_padding_top); int paddingBottom = r.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_content_padding_bottom); sv.SetClipToPadding(false); if (innerView is EditText) { sv.SetPadding(framePadding, paddingTop, framePadding, paddingBottom); } else { sv.SetPadding(0, paddingTop, 0, paddingBottom); innerView.SetPadding(framePadding, 0, framePadding, 0); } sv.AddView(innerView, new ScrollView.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)); innerView = sv; } frame.AddView(innerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)); } if (builder.ShowListener != null) { dialog.SetOnShowListener(builder.ShowListener); } if (builder.CancelListener != null) { dialog.SetOnCancelListener(builder.CancelListener); } if (builder.DismissListener != null) { dialog.SetOnDismissListener(builder.DismissListener); } if (builder.KeyListener != null) { dialog.SetOnKeyListener(builder.KeyListener); } dialog.SetOnShowListenerInternal(); dialog.InvalidateList(); dialog.SetViewInternal(dialog.GetView()); dialog.CheckIfListInitScroll(); }