void Init() { size = 50; rnd = new Random(); //speed = 8; speed = 32; snakeMaxLength = 100; foodTimerCount = 99; var foodPaint = new Paint(); foodPaint.SetARGB(255, 255, 0, 0); foodPaint.SetStyle(Paint.Style.Fill); food = new ShapeDrawable(new OvalShape()); food.Paint.Set(foodPaint); var snakePaint = new Paint(); snakePaint.SetARGB(255, 0, 0, 255); snakePaint.SetStyle(Paint.Style.Fill); snakeHead = new ShapeDrawable(new OvalShape()); snakeHead.Paint.Set(snakePaint); snakeBody = new Dictionary <int, ShapeDrawable>(); }
/// <summary> /// Setup the gradient layer /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs <GradientContentView> e) { base.OnElementChanged(e); if (GradientContentView != null) { ShapeDrawable = new ShapeDrawable(new RoundRectShape(new float[] { 8, 8, 8, 8, 8, 8, 8, 8 }, null, null)); GradientDrawable = new GradientDrawable(); GradientDrawable.SetColors(new int[] { GradientContentView.StartColor.ToAndroid(), GradientContentView.EndColor.ToAndroid() }); //this.SetBackgroundResource(Resource.Drawable.); // var gradient1 = new GradientDrawable(GradientDrawable.Orientation.TopBottom, new[] { // Color.FromRgba(255, 255, 255, 255).ToAndroid().ToArgb(), // Color.FromRgba(70, 70, 70, 50).ToAndroid().ToArgb() //}); // GradientDrawable.SetCornerRadius(270); // var element = (GradientContentView)e.NewElement; // var linearGradientBrush = new LinearGradientBrush(); // var linearGradientBrush = new LinearGradientBrush((System.Windows.Media.Color)ColorConverter.ConvertFromString("#FFDFD991"), (System.Windows.Media.Color)ColorConverter.ConvertFromString("#FFDFD991"),(double)220); //var linearGradientBrush = new LinearGradientBrush(new GradientStopCollection() //{ new GradientStop() { Color =new System.Windows.Media.Color.() }, //new GradientStop() { Color = new Windows.UI.Color() { A = Convert.ToByte((element.EndColor.A)*255), B = Convert.ToByte((element.EndColor.B)*255), G = Convert.ToByte((element.EndColor.G)*255), R= Convert.ToByte((element.EndColor.R)*255) }, Offset = 1 } }, 90); //linearGradientBrush.StartPoint = new Windows.Foundation.Point(0, 0); //linearGradientBrush.EndPoint = new Windows.Foundation.Point(0, 1); // GradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop); // Background = GradientDrawable; } }
private void SetBorder(ColorDatePicker view) { if (view.HasCorner) { int lefttop = (int)(view.CornerWidth * disp.Density); int righttop = lefttop; int leftbottom = lefttop; int rightbottom = lefttop; RoundRectShape rect = new RoundRectShape( new float[] { lefttop, lefttop, righttop, righttop, rightbottom, rightbottom, leftbottom, leftbottom }, null, null); ShapeDrawable bg = new ShapeDrawable(rect); bg.Paint.Color = view.BackgroundColor.ToAndroid(); Control.Background = bg; } else { Control.Background = originalDrawable; } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Slider> e) { base.OnElementChanged(e); if (Control == null) { throw new Exception("Control is null!"); } // while we're here, set the thumb circle size to something we can actually see and use!! // all this is excitingly flexible, yet depressingly difficult to discover! ShapeDrawable th = new ShapeDrawable(new OvalShape()); th.SetIntrinsicWidth(100); th.SetIntrinsicHeight(100); th.SetColorFilter(Android.Graphics.Color.Red, Android.Graphics.PorterDuff.Mode.SrcOver); Control.SetThumb(th); if (e.OldElement != null) { // Unsubscribe Control.SetOnSeekBarChangeListener(null); } if (e.NewElement != null) { // Subscribe Control.SetOnSeekBarChangeListener(Fork); } }
public CircleImageView(Context context, int color, float radius) : base(context) { var density = Context.Resources.DisplayMetrics.Density; var diameter = (int)(radius * density * 2); var shadowYOffset = (int)(density * YOffset); var shadowXOffset = (int)(density * XOffset); _shadowRadius = (int)(density * ShadowRadius); ShapeDrawable circle; if (ElevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.SetElevation(this, ShadowElevation * density); } else { OvalShape oval = new OvalShadow(this, _shadowRadius, diameter); circle = new ShapeDrawable(oval); #pragma warning disable 618 ViewCompat.SetLayerType(this, ViewCompat.LayerTypeSoftware, circle.Paint); #pragma warning restore 618 circle.Paint.SetShadowLayer(_shadowRadius, shadowXOffset, shadowYOffset, new Color(KeyShadowColor)); var padding = _shadowRadius; SetPadding(padding, padding, padding, padding); } circle.Paint.Color = new Color(color); #pragma warning disable 618 SetBackgroundDrawable(circle); #pragma warning restore 618 }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { var element = (CustomEntry)Element; HasUnderline = element.HasUnderline; var BorderClr = element.BorderColor.ToAndroid(); if (HasUnderline == false) { GradientDrawable gd = new GradientDrawable(); gd.SetColor(Android.Graphics.Color.Transparent); Control.SetBackgroundDrawable(gd); } if (BorderClr != Android.Graphics.Color.Transparent) { int borderThickness = element.BorderThickness; if (borderThickness == 0) { borderThickness = 1; } //in case border thickness was not set then default to 1 var brdr = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape()); brdr.Paint.Color = BorderClr; brdr.Paint.SetStyle(Paint.Style.Stroke); Control.Background = brdr; GradientDrawable gd = new GradientDrawable(); gd.SetColor(Android.Graphics.Color.Transparent); gd.SetStroke(borderThickness, BorderClr); Control.SetBackground(gd); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Editor> e) { base.OnElementChanged(e); if (e.NewElement != null) { MyEditor entity = e.NewElement as MyEditor; this.Control.Hint = entity.Placeholder; this.Control.SetHintTextColor(entity.PlaceholderColor.ToAndroid()); ShapeDrawable shape = new ShapeDrawable(new RectShape()); shape.Paint.Color = Xamarin.Forms.Color.Transparent.ToAndroid(); shape.Paint.StrokeWidth = 5; shape.Paint.SetStyle(Paint.Style.Stroke); this.Control.SetBackground(shape); //Control.SetLines(4); //Control.VerticalScrollBarEnabled = true; //Control.MovementMethod = ScrollingMovementMethod.Instance; //Control.ScrollBarStyle = ScrollbarStyles.InsideInset; ////Force scrollbars to be displayed //TypedArray a = Control.Context.Theme.ObtainStyledAttributes(new int[0]); //InitializeScrollbars(a); //a.Recycle(); } }
protected ShapeDrawable GradientConverter(String Gradient) { float[] array = new float[] { 250, 250, 250, 250, 250, 250, 250, 250 }; if (Base.CornerRadius != "-1") { var cornerRad = Base.CornerRadius.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); array = new float[] { BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[0])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[1])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[2])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[3])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[4])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[5])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[6])), BaseUIHelper.ConvertDPToPixels(float.Parse(cornerRad[7])) }; } ShapeDrawable sf = new ShapeDrawable(new RoundRectShape(array, null, null)); // sf.SetIntrinsicHeight(100); //sf.SetIntrinsicWidth(200); sf.SetShaderFactory(new GradientShader(Gradient)); if (Base.HasBorder) { sf.Paint.StrokeWidth = 1; sf.Paint.Color = Base.BorderColor.ToAndroid(); } return(sf); }
public override View GetView(int position, View convertView, ViewGroup parent) { TextView textView; if (convertView == null) { // if it's not recycled, initialize some attributes textView = new TextView(context); textView.LayoutParameters = new LinearLayout.LayoutParams(width / 3, height / 15); textView.Gravity = GravityFlags.Center; var shape = new ShapeDrawable(new RectShape()); shape.Paint.Color = Color.White; shape.Paint.StrokeWidth = 1; shape.Paint.SetStyle(Paint.Style.Stroke); textView.SetPadding(0, 5, 0, 5); textView.SetBackgroundDrawable(shape); } else { textView = (TextView)convertView; } //textView.SetText(thumbIds[position]); textView.Text = thumbIds[position]; return(textView); }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); var view = (BorderPicker)Element; if (e.PropertyName == "SelectedIndex" && isFirstLoaded) { int selectIndex = picker.SelectedIndex; picker = sender as BorderPicker; IList <string> scaleNames = picker.Items; ConvertToNative(scaleNames, picker); isFirstLoaded = false; if (selectIndex > 0) { initSelectedIndex = selectIndex; } } if (e.PropertyName.Equals("Width") || e.PropertyName.Equals("Height")) { var nativeEditText = (global::Android.Widget.Spinner)Control; var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape()); shape.Paint.Color = view.BorderColor.ToAndroid(); shape.Paint.StrokeWidth = 10; shape.Paint.SetStyle(Android.Graphics.Paint.Style.Stroke); nativeEditText.Background = shape; } }
private ShapeDrawable GetRoundRectangleDrawableShape(bool isToggled) { var radius = ConvertDPToPixels(13); float[] radiusArray = new float[] { radius, radius, radius, radius, radius, radius, radius, radius }; Android.Graphics.Drawables.Shapes.RoundRectShape roundRectShape = null; if (isToggled) { roundRectShape = new Android.Graphics.Drawables.Shapes.RoundRectShape(radiusArray, null, null); } else { roundRectShape = new Android.Graphics.Drawables.Shapes.RoundRectShape(radiusArray, new RectF(4, 4, 4, 4), radiusArray); } ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); shapeDrawable.Paint.Color = (Element.IsEnabled) ? CustomColors.BlueButtonColor.ToAndroid() : Xamarin.Forms.Color.LightGray.ToAndroid(); shapeDrawable.Paint.StrokeWidth = 4; shapeDrawable.Paint.StrokeCap = Paint.Cap.Round; shapeDrawable.Paint.StrokeJoin = Paint.Join.Round; shapeDrawable.Paint.SetStyle(Paint.Style.Fill); return(shapeDrawable); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { var nativeEditText = (global::Android.Widget.EditText)Control; var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape()); shape.Paint.Color = Xamarin.Forms.Color.White.ToAndroid(); shape.Paint.SetStyle(Paint.Style.Stroke); shape.Paint.TextSize = 14; nativeEditText.Background = shape; GradientDrawable gd = new GradientDrawable(); gd.SetColor(Android.Graphics.Color.LightGray); gd.SetCornerRadius(5); gd.SetStroke(2, Android.Graphics.Color.Black); nativeEditText.SetBackground(gd); } //if (Control != null) //{ // GradientDrawable gd = new GradientDrawable(); // //this line sets the bordercolor // gd.SetColor(global::Android.Graphics.Color.Red); // this.Control.SetBackgroundDrawable(gd); // this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions); // Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.White)); //} }
private void SetPoints() { this.PointsContainer.RemoveAllViews(); var lp = new LinearLayout.LayoutParams(10, 10); lp.LeftMargin = 5; lp.RightMargin = 5; var shape = new OvalShape(); shape.Resize(10, 10); var dr = new ShapeDrawable(shape); dr.Paint.Color = DefaultPointColor.ToAndroid(); for (var i = 0; i < this.Element.Children.Count; i++) { var v = new AV.View(this.Context); //v.SetBackgroundDrawable(dr); v.Background = dr; this.PointsContainer.AddView(v, lp); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { var corners = new float[] { 75, 75, 75, 75, 75, 75, 75, 75 }; //Control.Background = new ColorDrawable(Android.Graphics.Color.Transparent); Control.Background = new ColorDrawable(Android.Graphics.Color.White); if (Control is EditText nativeEditText) { var shape = new ShapeDrawable(new RoundRectShape(corners, null, null)); shape.Paint.Color = Xamarin.Forms.Color.Black.ToAndroid(); shape.Paint.SetStyle(Paint.Style.Stroke); nativeEditText.Background = shape; }//else } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.DatePicker> e) { base.OnElementChanged(e); RoundRectShape i = new RoundRectShape( new float[] { 15, 15, 15, 15, 15, 15, 15, 15 }, null, new float[] { 15, 15, 15, 15, 15, 15, 15, 15 }); var shape = new ShapeDrawable(i); shape.Paint.Color = Xamarin.Forms.Color.White.ToAndroid(); shape.Paint.SetStyle(Paint.Style.Stroke); Control.Background = shape; Control.SetPadding(15, 15, 15, 15); DatePickerBorderCtrl element = Element as DatePickerBorderCtrl; if (!string.IsNullOrWhiteSpace(element.Placeholder)) { this.Control.SetTextColor(Android.Graphics.Color.Gray); Control.Text = element.Placeholder; } this.Control.TextChanged += (sender, arg) => { var selectedDate = arg.Text.ToString(); if (selectedDate == element.Placeholder) { Control.Text = DateTime.Now.ToString("dd/MM/yyyy"); //this.Control.SetTextColor(Android.Graphics.Color.Gray); } }; }
protected override void OnElementChanged(ElementChangedEventArgs <ContentView> e) { base.OnElementChanged(e); if (e.OldElement != null) { return; } if (e.NewElement != null) { var element = e.NewElement as ContentViewWithBorder; _borderShape = new ShapeDrawable( new Android.Graphics.Drawables.Shapes.RoundRectShape(new[] { (float)element.CornerRadius, (float)element.CornerRadius, (float)element.CornerRadius, (float)element.CornerRadius, (float)element.CornerRadius, (float)element.CornerRadius, (float)element.CornerRadius, (float)element.CornerRadius }, null, null)); var paint = new Paint(PaintFlags.AntiAlias) { Color = element.BorderColor.ToAndroid(), StrokeWidth = (float)element.BorderWidth * 2.5f, StrokeMiter = 10f }; _borderShape.Paint.Set(paint); _borderShape.Paint.SetStyle(Paint.Style.Stroke); Background = _borderShape; } }
public static ShapeDrawable Circle() { ShapeDrawable drw = new ShapeDrawable(new OvalShape()); drw.Paint.Color = Color.White; return(drw); }
private static ShapeDrawable createRoundedIndicator(Color color) { var drawable = new ShapeDrawable(new OvalShape()); drawable.Paint.Color = color.ToNative(); return(drawable); }
/// <summary> /// Initializes the joystick and displacement shapes /// </summary> private void InitShapes() { // Paint for joystick ovals var paintStick = new Paint(); paintStick.SetARGB(255, 78, 78, 78); paintStick.SetStyle(Paint.Style.Fill); // Shape for left joystick m_ShapeStickLeft = new ShapeDrawable(new OvalShape()); m_ShapeStickLeft.Paint.Set(paintStick); // Shape for right joystick m_ShapeStickRight = new ShapeDrawable(new OvalShape()); m_ShapeStickRight.Paint.Set(paintStick); // Paint for displacement ovals var paintRadius = new Paint(); paintRadius.SetARGB(255, 230, 230, 230); paintRadius.SetStyle(Paint.Style.Fill); // Shape for left displacement m_ShapeRadiusLeft = new ShapeDrawable(new OvalShape()); m_ShapeRadiusLeft.Paint.Set(paintRadius); // Shape for right displacement m_ShapeRadiusRight = new ShapeDrawable(new OvalShape()); m_ShapeRadiusRight.Paint.Set(paintRadius); }
public CircleImageView(Context context, int color, float radius) : base(context) { float density = Context.Resources.DisplayMetrics.Density; int diameter = (int)(radius * density * 2); int shadowYOffset = (int)(density * Y_OFFSET); int shadowXOffset = (int)(density * X_OFFSET); mShadowRadius = (int)(density * SHADOW_RADIUS); ShapeDrawable circle; if (elevationSupported()) { circle = new ShapeDrawable(new OvalShape()); ViewCompat.SetElevation(this, SHADOW_ELEVATION * density); } else { OvalShape oval = new OvalShadow(this, mShadowRadius, diameter); circle = new ShapeDrawable(oval); ViewCompat.SetLayerType(this, ViewCompat.LayerTypeSoftware, circle.Paint); circle.Paint.SetShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, new Color(KEY_SHADOW_COLOR)); int padding = mShadowRadius; // set padding so the inner image sits correctly within the shadow. SetPadding(padding, padding, padding, padding); } circle.Paint.Color = new Color(color); SetBackgroundDrawable(circle); }
private static ShapeDrawable Circle(Color color) { var circle = new ShapeDrawable(new OvalShape()); circle.Paint.Color = color; return(circle); }
void SwitchButtonColor() { ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); drawable.Paint.Color = Element.ButtonColor.ToAndroid(); takePhotoButton.Background = drawable; }
protected override View GetCellCore(Cell item, View convertView, ViewGroup parent, Context context) { var cell = (LinearLayout)base.GetCellCore(item, convertView, parent, context); cell.SetPadding(20, 10, 0, 10); cell.DividerPadding = 50; var div = new ShapeDrawable(); div.SetIntrinsicHeight(1); //div.Paint.Set(new Paint { Color = Color.FromHex("00FFFFFF").ToAndroid() }); if (parent is ListView) { ((ListView)parent).Divider = div; ((ListView)parent).DividerHeight = 1; } var label = (TextView)((LinearLayout)cell.GetChildAt(1)).GetChildAt(0); label.SetTextColor(Color.FromHex("000000").ToAndroid()); label.TextSize = Font.SystemFontOfSize(NamedSize.Large).ToScaledPixel(); var secondaryLabel = (TextView)((LinearLayout)cell.GetChildAt(1)).GetChildAt(1); secondaryLabel.SetTextColor(Color.FromHex("738182").ToAndroid()); secondaryLabel.TextSize = Font.SystemFontOfSize(NamedSize.Medium).ToScaledPixel(); return(cell); }
public PagerAnimatedAdapter(IList <TData> dataCollection, ViewInflatHandler viewInflater, ShapeDrawable shapeBackground, ShapeDrawable shapeForeground, FragmentManager fm) : base(fm) { _dataCollection = dataCollection; _viewInflater = viewInflater; _shapeBackground = shapeBackground; _shapeForeground = shapeForeground; }
protected override void OnAttached() { var shape = new ShapeDrawable(new RectShape()); shape.Paint.Color = Android.Graphics.Color.Transparent; shape.Paint.StrokeWidth = 0; shape.Paint.SetStyle(Paint.Style.Stroke); Control.Background = shape; }
public ShapeDrawable RectBorder(Android.Graphics.Color borderColor, float borderWidth) { ShapeDrawable shape = new ShapeDrawable(new RectShape()); shape.Paint.Color = borderColor; shape.Paint.SetStyle(Paint.Style.Stroke); shape.Paint.StrokeWidth = borderWidth; return(shape); }
public static Drawable Circular(Color color) { ShapeDrawable drw = new ShapeDrawable(new OvalShape()); drw.SetIntrinsicHeight(100); drw.SetIntrinsicWidth(100); drw.Paint.Color = Color.White; return(new RippleDrawable(ColorStateList.ValueOf(color), null, drw)); }
public PagerAnimatedFragment(TData data, ViewInflatHandler viewInflater, PagerItemClickHandler itemClickHandler, ShapeDrawable shapeBackground, ShapeDrawable shapeForeground) { _data = data; _viewInflater = viewInflater; _itemClickHandler = itemClickHandler; _shapeBackground = shapeBackground; _shapeForeground = shapeForeground; }
private Drawable CreateCircleDrawable(Color color, int size = 100) { ShapeDrawable drw = new ShapeDrawable(new OvalShape()); drw.SetIntrinsicHeight(size); drw.SetIntrinsicWidth(size); drw.Paint.Color = color; return(drw); }
public static ShapeDrawable Circle(int intrinsicSize) { ShapeDrawable drw = new ShapeDrawable(new OvalShape()); drw.SetIntrinsicHeight(intrinsicSize); drw.SetIntrinsicWidth(intrinsicSize); drw.Paint.Color = Color.White; return(drw); }